parser.go 935 B

12345678910111213141516171819202122232425262728293031323334
  1. package magento
  2. import (
  3. "kkscrap-go/controllers/scraper/common"
  4. "kkscrap-go/model"
  5. "strings"
  6. util "kkscrap-go/controllers/scraper/util"
  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. doc.Find("meta").Each(func(i int, s *goquery.Selection) {
  14. v, _ := s.Attr("property")
  15. if v == "og:description" {
  16. item.ShortDesc = s.AttrOr("content", "")
  17. } else if v == "og:title" {
  18. item.ItemName = s.AttrOr("content", "")
  19. } else if v == "og:image" {
  20. item.Images = append(item.Images, s.AttrOr("content", ""))
  21. } else if v == "product:price:amount" {
  22. item.SalesPrice = util.GetFloat32(s.AttrOr("content", ""))
  23. } else if v == "product:price:currency" {
  24. item.Currency = s.AttrOr("content", "")
  25. }
  26. })
  27. item.Emails = common.GetEmails(body)
  28. return
  29. }