Skip to content

Commit

Permalink
Closes #24
Browse files Browse the repository at this point in the history
By using request-response context; See gocolly/colly#212 (comment)
  • Loading branch information
k4lizen committed Jul 31, 2023
1 parent e51c0a7 commit f982082
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/engines/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ func Search(ctx context.Context, query string, relay *structures.Relay, options
retError = err
return
}
r.Ctx.Put("originalURL", r.URL.String())
})

pagesCol.OnError(func(r *colly.Response, err error) {
retError = err
})

pagesCol.OnResponse(func(r *colly.Response) {
urll := strings.ToLower(r.Request.URL.String()) //temporary hack, read comment in col.OnHTML
urll := r.Ctx.Get("originalURL")

setResultResponse(urll, r, relay)
})
Expand All @@ -79,7 +80,6 @@ func Search(ctx context.Context, query string, relay *structures.Relay, options

linkHref, _ := dom.Find("a").Attr("href")
linkText := strings.TrimSpace(linkHref)
linkText = strings.ToLower(linkText) // r.Request.URL.String() in pageCol is SOMETIMES lowercase, making this lowercase as well to compensate - temporary fix until better solution is found, since urls are case sensitive https://stackoverflow.com/questions/7996919/should-url-be-case-sensitive
titleText := strings.TrimSpace(dom.Find("div > div > div > a > h3").Text())
descText := strings.TrimSpace(dom.Find("div > div > div > div:first-child > span:first-child").Text())

Expand Down

0 comments on commit f982082

Please sign in to comment.