random geolocation for search, tmp
This commit is contained in:
parent
624d3137e0
commit
cdc4c60618
1 changed files with 16 additions and 1 deletions
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -69,8 +70,22 @@ func buildSearchURL(query, safe, lang string, page, resultsPerPage int) string {
|
||||||
langParam = "&lr=" + lang
|
langParam = "&lr=" + lang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate random geolocation
|
||||||
|
glParam, uuleParam := getRandomGeoLocation()
|
||||||
|
|
||||||
startIndex := (page - 1) * resultsPerPage
|
startIndex := (page - 1) * resultsPerPage
|
||||||
return fmt.Sprintf("https://www.google.com/search?q=%s%s%s&udm=14&start=%d", url.QueryEscape(query), safeParam, langParam, startIndex)
|
return fmt.Sprintf("https://www.google.com/search?q=%s%s%s%s%s&start=%d",
|
||||||
|
url.QueryEscape(query), safeParam, langParam, glParam, uuleParam, startIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRandomGeoLocation() (string, string) {
|
||||||
|
countries := []string{"us", "ca", "gb", "fr", "de", "au", "in", "jp", "br", "za"}
|
||||||
|
randomCountry := countries[rand.Intn(len(countries))]
|
||||||
|
|
||||||
|
glParam := "&gl=" + randomCountry
|
||||||
|
uuleParam := ""
|
||||||
|
|
||||||
|
return glParam, uuleParam
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseResults(doc *goquery.Document) []TextSearchResult {
|
func parseResults(doc *goquery.Document) []TextSearchResult {
|
||||||
|
|
Loading…
Add table
Reference in a new issue