main.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "regexp"
  7. "github.com/PuerkitoBio/goquery"
  8. )
  9. func main() {
  10. // Wordpress
  11. // url := "https://addand.kr/shop/new-%ed%95%9c-%ea%b6%8c%ec%9c%bc%eb%a1%9c-%eb%81%9d%eb%82%98%eb%8a%94-%eb%85%b8%ec%85%98/"
  12. url := "https://www.cafe24h.com.vn/ca-phe-truyen-thong/"
  13. url = "https://ssline.kr/shop/view.php?index_no=36357" //cafe24
  14. url = "https://fcentermall.co.kr/shop/view.php?index_no=114" //cafe24
  15. // url := "https://bt-beloria-1.myshopify.com/collections/women-collection/products/sweater-classical-tshirt"
  16. // url := "https://seoulknit.com/shop/v-neck-summer-pullover/"
  17. // url = "https://www.elcanto.co.kr" //MakeShop
  18. // url = "https://www.ippngirl.co.kr" //MakeShop
  19. // url = "https://bt-beloria-1.myshopify.com" //shopify
  20. // url = "https://lachinatakorea.com" //Godomall
  21. // url = "https://sf-fd.com" //Godomall
  22. // url = "https://www.vanillagift.com" //Magento
  23. // url = "https://taiwan.coach.com" //Magento
  24. // url = "http://mas1.magikthemes.com" //Magento
  25. // url = "https://aladinmarket.co.kr" //young Cart
  26. // url = "http://damoagift.com" //young Cart
  27. // url = "https://p2u.daboryhost.com" /DaboryShop
  28. // url = "https://seoulknit.com" //Woocommerce
  29. // url = "http://webhost.dabory.com/" /Woocommerce
  30. // url = "https://addand.kr" // WooCommerce
  31. // url := "https://droppii.net.vn/cnd-ginseng-gold"
  32. // Send an HTTP GET request to the URL
  33. response, err := http.Get(url)
  34. if err != nil {
  35. log.Fatal(err)
  36. }
  37. defer response.Body.Close()
  38. doc, err := goquery.NewDocumentFromReader(response.Body)
  39. if err != nil {
  40. log.Fatal(err)
  41. }
  42. // Use the Find method to select elements that match the css selector
  43. // doc.Find(cItemName).Each(func(index int, element *goquery.Selection) {
  44. // // Extract the text associated with the selected element
  45. // text := element.Text()
  46. // fmt.Printf("Text associated with %s: %s\n", cItemName, text)
  47. // })
  48. doc.Find("meta").Each(func(i int, s *goquery.Selection) {
  49. v, _ := s.Attr("property")
  50. if v == "author" {
  51. fmt.Println("Author : ", s.AttrOr("content", ""))
  52. }
  53. if v == "og:title" {
  54. fmt.Println("og:title: ", s.AttrOr("content", ""))
  55. }
  56. if v == "og:description" {
  57. fmt.Println("description: ", s.AttrOr("content", ""))
  58. }
  59. if v == "og:image" {
  60. fmt.Println("og:image: ", s.AttrOr("content", ""))
  61. }
  62. })
  63. fmt.Println("///////////////////////")
  64. // These will the value of PDP parsing structures
  65. cItemName := ".vi_txt_bx .tit"
  66. cShortDesc := ".vi_tab:last"
  67. cItemCategory := ".container>.section-header>.section-title"
  68. // cItemTags := ".vi_tab"
  69. cItemImages := ".vi_info .vi_img_bx .bimg"
  70. // cItemImages := "bimg"
  71. // cItemImages := ".vi_info .simg_li img"
  72. cItemTextDesc := ".mart15>.__se_tbl_ext"
  73. // // cItemOptions := "select#rating option"
  74. cItemPrice := ".price_bx .price"
  75. // cEmail := "footer"
  76. // cRating := ".star-rating .rating"
  77. // cAuthor := ".product-brand a"
  78. // cVideo := "iframe"
  79. fmt.Println("ItemImage-1: ", doc.Find(cItemImages).First().Text())
  80. fmt.Println("ItemName: ", doc.Find(cItemName).First().Text())
  81. fmt.Println("ShortDesc: ", doc.Find(cShortDesc).First().Text())
  82. fmt.Println("ItemCategory: ", doc.Find(cItemCategory).First().Text())
  83. // fmt.Println("ItemTags: ", doc.Find(cItemTags).First().Text())
  84. fmt.Println("TextDesc: ", doc.Find(cItemTextDesc).First().Text())
  85. fmt.Println("ItemPrice: ", doc.Find(cItemPrice).First().Text())
  86. // fmt.Println("Email: ", findEmail(doc.Find(cEmail).First().Text(), ""))
  87. // fmt.Println("Rating : ", doc.Find(cRating).First().Text())
  88. // doc.Find("meta").Each(func(i int, s *goquery.Selection) {
  89. // v, _ := s.Attr("property")
  90. // fmt.Println(v, " : ", s.AttrOr("content", ""))
  91. // })
  92. // doc.Find(cAuthor).Each(func(index int, element *goquery.Selection) {
  93. // link, _ := element.Attr("href")
  94. // fmt.Println("====================")
  95. // fmt.Println("AuthorName: ", element.Text())
  96. // fmt.Printf("AuthorLink: %s\n", link)
  97. // })
  98. // vdos := []string{}
  99. // doc.Find(cVideo).Each(func(index int, element *goquery.Selection) {
  100. // embed, _ := element.Attr("src")
  101. // vdos = append(vdos, embed)
  102. // })
  103. // fmt.Printf("ItemVideos: %s\n", vdos)
  104. imgs := []string{}
  105. doc.Find(cItemImages).Each(func(index int, element *goquery.Selection) {
  106. img, _ := element.Attr("img")
  107. imgs = append(imgs, img)
  108. })
  109. fmt.Println("ItemImages: ", imgs)
  110. }
  111. func findEmail(body string, doms string) (emails []string) {
  112. r, _ := regexp.Compile(`[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,24}`)
  113. emails = append(emails, r.FindStringSubmatch(body)...)
  114. return
  115. }