-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from chrisjoyce911/useragent
Update User Agent
- Loading branch information
Showing
5 changed files
with
155 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package googlesearch | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func ExampleSearch() { | ||
|
||
opt := SearchOptions{ | ||
CountryCode: "au", | ||
} | ||
|
||
//lint:ignore SA1012 ignore this bare essentials by passing nil for context and removing context package (despite not being idiomatic go). | ||
serp, err := Search(nil, "First Aid Course Australia Wide First Aid", opt) | ||
|
||
if err != nil { | ||
fmt.Print(err.Error()) | ||
} | ||
|
||
for _, result := range serp { | ||
if strings.Contains(result.URL, "australiawidefirstaid.com.au") { | ||
fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") | ||
break | ||
} | ||
} | ||
|
||
// Output: Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp | ||
|
||
} | ||
|
||
/* | ||
Example of how to set the useragent | ||
*/ | ||
func ExampleUserAgent() { | ||
|
||
// whatismybrowser.com maintains a database of UserAgents | ||
// https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome | ||
|
||
opt := SearchOptions{ | ||
CountryCode: "au", | ||
UserAgent: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36", | ||
} | ||
|
||
//lint:ignore SA1012 ignore this bare essentials by passing nil for context and removing context package (despite not being idiomatic go). | ||
serp, err := Search(nil, "First Aid Course Australia Wide First Aid", opt) | ||
|
||
if err != nil { | ||
fmt.Print(err.Error()) | ||
} | ||
|
||
for _, result := range serp { | ||
if strings.Contains(result.URL, "australiawidefirstaid.com.au") { | ||
fmt.Println("Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp") | ||
break | ||
} | ||
} | ||
|
||
// Output: Australia Wide First Aid (https://www.australiawidefirstaid.com.au/) found in the serp | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
module github.com/rocketlaunchr/google-search | ||
|
||
go 1.12 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/gocolly/colly/v2 v2.1.0 | ||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 | ||
golang.org/x/time v0.3.0 | ||
) | ||
|
||
require ( | ||
github.com/PuerkitoBio/goquery v1.8.1 // indirect | ||
github.com/andybalholm/cascadia v1.3.2 // indirect | ||
github.com/antchfx/htmlquery v1.3.0 // indirect | ||
github.com/antchfx/xmlquery v1.3.15 // indirect | ||
github.com/antchfx/xpath v1.2.4 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect | ||
github.com/temoto/robotstxt v1.1.2 // indirect | ||
golang.org/x/net v0.10.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.