parser.go 986 B

12345678910111213141516171819202122232425262728293031323334
  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(body string, item *model.ItemInfo) {
  10. item.Language = common.GetLanguage(body)
  11. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  12. util.CheckError(err)
  13. //s := doc.Find("meta[property=\"og:url\"]")
  14. doc.Find("link ~ meta").Each(func(i int, s *goquery.Selection) {
  15. v, _ := s.Attr("property")
  16. if v == "og:description" {
  17. item.ShortDesc = s.AttrOr("content", "")
  18. } else if v == "og:title" {
  19. item.ItemName = s.AttrOr("content", "")
  20. } else if v == "og:image" {
  21. item.Images = append(item.Images, s.AttrOr("content", ""))
  22. } else if v == "product:price:amount" {
  23. item.SalesPrice = util.GetFloat32(s.AttrOr("content", ""))
  24. } else if v == "product:price:currency" {
  25. item.Currency = s.AttrOr("content", "")
  26. }
  27. })
  28. item.Emails = common.GetEmails(body)
  29. return
  30. }