From 04fb0ca62938053ae42cb7a91a36107eaa3bcfcd Mon Sep 17 00:00:00 2001 From: partisan Date: Mon, 12 Aug 2024 17:02:17 +0200 Subject: [PATCH] random geolocation for search, tmp --- text-google.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/text-google.go b/text-google.go index ce7646f..98cf897 100644 --- a/text-google.go +++ b/text-google.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math/rand" "net/http" "net/url" "strings" @@ -69,8 +70,22 @@ func buildSearchURL(query, safe, lang string, page, resultsPerPage int) string { langParam = "&lr=" + lang } + // Generate random geolocation + glParam, uuleParam := getRandomGeoLocation() + 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 {