- update pkg for new DOM change
This commit is contained in:
parent
80e6c4a00a
commit
14d80b5b0d
40
search.go
40
search.go
@ -298,36 +298,26 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re
|
|||||||
rErr = err
|
rErr = err
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// https://www.w3schools.com/cssref/css_selectors.asp
|
||||||
c.OnHTML("div.g", func(e *colly.HTMLElement) {
|
c.OnHTML("div.g", func(e *colly.HTMLElement) {
|
||||||
|
|
||||||
sel := e.DOM
|
sel := e.DOM
|
||||||
|
|
||||||
for i := range sel.Nodes {
|
linkHref, _ := sel.Find("a").Attr("href")
|
||||||
if err := ctx.Err(); err != nil {
|
linkText := strings.TrimSpace(linkHref)
|
||||||
rErr = err
|
titleText := strings.TrimSpace(sel.Find("div > div > a > h3 > span").Text())
|
||||||
return
|
|
||||||
}
|
descText := strings.TrimSpace(sel.Find("div > div > div > span > span").Text())
|
||||||
|
|
||||||
item := sel.Eq(i)
|
if linkText != "" && linkText != "#" {
|
||||||
|
result := Result{
|
||||||
rDiv := item.Find("div.rc")
|
Rank: rank,
|
||||||
|
URL: linkText,
|
||||||
linkHref, _ := rDiv.Find("a").Attr("href")
|
Title: titleText,
|
||||||
linkText := strings.TrimSpace(linkHref)
|
Description: descText,
|
||||||
titleText := strings.TrimSpace(rDiv.Find("h3").Text())
|
|
||||||
|
|
||||||
descText := strings.TrimSpace(rDiv.Find("div > div > span > span").Text())
|
|
||||||
|
|
||||||
if linkText != "" && linkText != "#" {
|
|
||||||
result := Result{
|
|
||||||
Rank: rank,
|
|
||||||
URL: linkText,
|
|
||||||
Title: titleText,
|
|
||||||
Description: descText,
|
|
||||||
}
|
|
||||||
results = append(results, result)
|
|
||||||
rank += 1
|
|
||||||
}
|
}
|
||||||
|
results = append(results, result)
|
||||||
|
rank += 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user