package godo import ( "kkscrap-go/controllers/scraper/common" "kkscrap-go/model" "regexp" "strings" util "kkscrap-go/controllers/scraper/util" "github.com/PuerkitoBio/goquery" ) func Parse(uri string, item *model.ItemInfo) { body, err := util.Get(uri) util.CheckError(err) item.Language = getLanguage(body) doc, err := goquery.NewDocumentFromReader(strings.NewReader(body)) util.CheckError(err) doc.Find("meta").Each(func(i int, s *goquery.Selection) { v, _ := s.Attr("property") if v == "og:title" { item.ItemName = s.AttrOr("content", "") } else if v == "og:image" { item.Images = append(item.Images, s.AttrOr("content", "")) } else if v == "product:price:amount" { item.SalesPrice = util.GetFloat32(s.AttrOr("content", "")) } else if v == "product:price:currency" { item.Currency = s.AttrOr("content", "") } }) desc := doc.Find("#frmView > div > div > div.item_detail_tit > div").Text() if desc != "" { desc = strings.Split(desc, "\n")[0] } item.ShortDesc = desc item.SalesPrice = getPrice(body) item.Currency = getCurrency(body) item.Emails = common.GetEmails(body) return } func getLanguage(body string) string { reg, _ := regexp.Compile("var gdLocale = '(.*)';") ss := reg.FindStringSubmatch(body) return ss[1] } func getCurrency(body string) string { reg, _ := regexp.Compile("var gdCurrencyCode = '(.*)';") ss := reg.FindStringSubmatch(body) return ss[1] } func getPrice(body string) float32 { reg, _ := regexp.Compile("'setGoodsPrice'[ ]*:[ ]*'(.*)'") ss := reg.FindStringSubmatch(body) return util.GetFloat32(ss[1]) }