parser.go 985 B

12345678910111213141516171819202122232425262728293031323334353637
  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(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. doc.Find("meta").Each(func(i int, s *goquery.Selection) {
  16. v, _ := s.Attr("property")
  17. if v == "og:description" {
  18. item.ShortDesc = s.AttrOr("content", "")
  19. } else if v == "og:title" {
  20. item.ItemName = s.AttrOr("content", "")
  21. } else if v == "og:image" {
  22. item.Images = append(item.Images, s.AttrOr("content", ""))
  23. } else if v == "product:price:amount" {
  24. item.SalesPrice = util.GetFloat32(s.AttrOr("content", ""))
  25. } else if v == "product:price:currency" {
  26. item.Currency = s.AttrOr("content", "")
  27. }
  28. })
  29. item.Emails = common.GetEmails(body)
  30. return
  31. }