WIP
This commit is contained in:
parent
8212b071ec
commit
ac8c22aadd
@ -62,8 +62,10 @@ func (tabelog) index(doc *goquery.Document) (string, []string) {
|
||||
}
|
||||
|
||||
func (tabelog) review(doc *goquery.Document) (name, address string, features map[string]float64, weight float64, err error) {
|
||||
weight = 1.0
|
||||
name = doc.Find("a.rd-header__rst-name-main").Text()
|
||||
if name = doc.Find("a.rd-header__rst-name-main").Text(); len(name) == 0 {
|
||||
err = errors.New("invalid value for name")
|
||||
return
|
||||
}
|
||||
|
||||
if addresses := doc.Find("p.rd-detail-info__rst-address"); addresses.Length() == 2 {
|
||||
address = strings.TrimSpace(addresses.First().Text())
|
||||
@ -73,9 +75,8 @@ func (tabelog) review(doc *goquery.Document) (name, address string, features map
|
||||
}
|
||||
|
||||
features = make(map[string]float64)
|
||||
|
||||
for index, category := range []string{"dishes", "service", "atmosphere", "cost", "drinks"} {
|
||||
valueText := doc.Find(fmt.Sprintf("#js-rating-detail > dd:nth-child(%d)", (index+1)*2)).Text()
|
||||
valueText := doc.Find(fmt.Sprintf("dl#js-rating-detail > dd:nth-child(%d)", (index+1)*2)).Text()
|
||||
|
||||
var value float64
|
||||
if value, err = strconv.ParseFloat(valueText, 8); err != nil {
|
||||
@ -86,5 +87,11 @@ func (tabelog) review(doc *goquery.Document) (name, address string, features map
|
||||
features[category] = value/2.5 - 1.0
|
||||
}
|
||||
|
||||
weight, err = strconv.ParseFloat(doc.Find("a.rd-header__rst-reviews-target > b").Text(), 8)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("invalid value for review count")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -61,9 +61,15 @@ func (tripadvisor) index(doc *goquery.Document) (string, []string) {
|
||||
}
|
||||
|
||||
func (tripadvisor) review(doc *goquery.Document) (name, address string, features map[string]float64, weight float64, err error) {
|
||||
weight = 1.0
|
||||
name = strings.TrimSpace(doc.Find("h1#HEADING").Text())
|
||||
address = strings.TrimSpace(doc.Find("address span.format_address").Text())
|
||||
if name = strings.TrimSpace(doc.Find("h1#HEADING").Text()); len(name) == 0 {
|
||||
err = errors.New("invalid value for name name")
|
||||
return
|
||||
}
|
||||
|
||||
if address = strings.TrimSpace(doc.Find("address span.format_address").Text()); len(address) == 0 {
|
||||
err = errors.New("invalid value for address")
|
||||
return
|
||||
}
|
||||
|
||||
ratings := doc.Find("ul.barChart div.ratingRow img.sprite-rating_s_fill")
|
||||
if ratings.Length() != 4 {
|
||||
@ -72,7 +78,6 @@ func (tripadvisor) review(doc *goquery.Document) (name, address string, features
|
||||
}
|
||||
|
||||
features = make(map[string]float64)
|
||||
|
||||
for index, category := range []string{"food", "service", "value", "atmosphere"} {
|
||||
altText, _ := ratings.Eq(index).Attr("alt")
|
||||
valueText := strings.Split(altText, " ")[0]
|
||||
@ -86,5 +91,16 @@ func (tripadvisor) review(doc *goquery.Document) (name, address string, features
|
||||
features[category] = value/2.5 - 1.0
|
||||
}
|
||||
|
||||
weightParts := strings.Split(doc.Find("h3.reviews_header").Text(), " ")
|
||||
if len(weightParts) == 0 {
|
||||
err = fmt.Errorf("missing review count")
|
||||
return
|
||||
}
|
||||
|
||||
if weight, err = strconv.ParseFloat(weightParts[0], 8); err != nil {
|
||||
err = fmt.Errorf("invalid value for review count")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user