fix for pages
This commit is contained in:
parent
6885983576
commit
a86b370f69
5 changed files with 99 additions and 157 deletions
|
@ -11,9 +11,9 @@ import (
|
|||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
func PerformDuckDuckGoTextSearch(query, safe, lang string) ([]TextSearchResult, error) {
|
||||
func PerformDuckDuckGoTextSearch(query, safe, lang string, page int) ([]TextSearchResult, error) {
|
||||
var results []TextSearchResult
|
||||
searchURL := fmt.Sprintf("https://duckduckgo.com/html/?q=%s", url.QueryEscape(query))
|
||||
searchURL := buildDuckDuckGoSearchURL(query, page)
|
||||
|
||||
resp, err := http.Get(searchURL)
|
||||
if err != nil {
|
||||
|
@ -56,3 +56,11 @@ func PerformDuckDuckGoTextSearch(query, safe, lang string) ([]TextSearchResult,
|
|||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func buildDuckDuckGoSearchURL(query string, page int) string {
|
||||
startParam := ""
|
||||
if page > 1 {
|
||||
startParam = fmt.Sprintf("&s=%d", (page-1)*10)
|
||||
}
|
||||
return fmt.Sprintf("https://duckduckgo.com/html/?q=%s%s", url.QueryEscape(query), startParam)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue