parser.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package cafe24
  2. import (
  3. "kkscrap-go/controllers/scraper/common"
  4. util "kkscrap-go/controllers/scraper/util"
  5. "kkscrap-go/model"
  6. "strings"
  7. "github.com/PuerkitoBio/goquery"
  8. )
  9. func Parse(uri string, item *model.ItemInfo) {
  10. body, err := util.Get(uri)
  11. util.CheckError(err)
  12. item.Language = common.GetLanguage(body)
  13. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  14. util.CheckError(err)
  15. //s := doc.Find("meta[property=\"og:url\"]")
  16. doc.Find("link ~ meta").Each(func(i int, s *goquery.Selection) {
  17. v, _ := s.Attr("property")
  18. if v == "og:description" {
  19. item.ShortDesc = s.AttrOr("content", "")
  20. } else if v == "og:title" {
  21. item.ItemName = s.AttrOr("content", "")
  22. } else if v == "og:image" {
  23. item.Images = append(item.Images, s.AttrOr("content", ""))
  24. } else if v == "product:price:amount" {
  25. item.SalesPrice = util.GetFloat32(s.AttrOr("content", ""))
  26. } else if v == "product:price:currency" {
  27. item.Currency = s.AttrOr("content", "")
  28. }
  29. })
  30. item.Emails = common.GetEmails(body)
  31. return
  32. }