From d479e26463df0e92af79062ffe624d1aa58fb0f9 Mon Sep 17 00:00:00 2001 From: miguelp Date: Sat, 8 Oct 2022 01:40:08 +0100 Subject: [PATCH 01/16] changed package name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 6e1ac9e..f4068c9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rocketlaunchr/google-search +module github.com/lookatitude/google-search go 1.12 From 257581fab67f5f532258e01419648d9489018875 Mon Sep 17 00:00:00 2001 From: miguelp Date: Sat, 8 Oct 2022 01:46:27 +0100 Subject: [PATCH 02/16] cahnged package name to be able to import from fork --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f4068c9..2ed8dd8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/lookatitude/google-search -go 1.12 +go 1.19 require ( github.com/gocolly/colly/v2 v2.1.0 From aaa2b13060a08db1123a72ff209a5e37bbccb77f Mon Sep 17 00:00:00 2001 From: miguelp Date: Sat, 8 Oct 2022 02:03:47 +0100 Subject: [PATCH 03/16] cahnged package name back to the original --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 2ed8dd8..6e1ac9e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/lookatitude/google-search +module github.com/rocketlaunchr/google-search -go 1.19 +go 1.12 require ( github.com/gocolly/colly/v2 v2.1.0 From 108aac8b0e67604431d660222b4fec0a7de58910 Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 14:56:25 +1000 Subject: [PATCH 04/16] Updated go, useragent and added example --- example/main.go | 13 ++++++++ go.mod | 24 ++++++++++++-- go.sum | 88 +++++++++++++++++++++++++++++++++++++++---------- search.go | 2 +- search_test.go | 2 +- 5 files changed, 107 insertions(+), 22 deletions(-) create mode 100644 example/main.go diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..17e72fc --- /dev/null +++ b/example/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "context" + "fmt" + + googlesearch "github.com/chrisjoyce911/google-search" +) + +func main() { + + fmt.Println(googlesearch.Search(context.Background(), "First Aid Course Australia Wide First Aid")) +} diff --git a/go.mod b/go.mod index 6e1ac9e..20fed7d 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,26 @@ -module github.com/rocketlaunchr/google-search +module github.com/chrisjoyce911/google-search -go 1.12 +go 1.20 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/gobwas/glob v0.2.3 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/kennygrant/sanitize v1.2.4 // 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 + golang.org/x/text v0.9.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.30.0 // indirect ) diff --git a/go.sum b/go.sum index c620646..2655b8a 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,24 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= +github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= -github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE= github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY= -github.com/antchfx/htmlquery v1.2.3 h1:sP3NFDneHx2stfNXCKbhHFo8XgNjCACnU/4AO5gWz6M= +github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= +github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= +github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= github.com/antchfx/htmlquery v1.2.3/go.mod h1:B0ABL+F5irhhMWg54ymEZinzMSi0Kt3I2if0BLYa3V0= -github.com/antchfx/xmlquery v1.2.4 h1:T/SH1bYdzdjTMoz2RgsfVKbM5uWh3gjDYYepFqQmFv4= +github.com/antchfx/htmlquery v1.3.0 h1:5I5yNFOVI+egyia5F2s/5Do2nFWxJz41Tr3DyfKD25E= +github.com/antchfx/htmlquery v1.3.0/go.mod h1:zKPDVTMhfOmcwxheXUsx4rKJy8KEY/PU6eXr/2SebQ8= github.com/antchfx/xmlquery v1.2.4/go.mod h1:KQQuESaxSlqugE2ZBcM/qn+ebIpt+d+4Xx7YcSGAIrM= +github.com/antchfx/xmlquery v1.3.15 h1:aJConNMi1sMha5G8YJoAIF5P+H+qG1L73bSItWHo8Tw= +github.com/antchfx/xmlquery v1.3.15/go.mod h1:zMDv5tIGjOxY/JCNNinnle7V/EwthZ5IT8eeCGJKRWA= github.com/antchfx/xpath v1.1.6/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= -github.com/antchfx/xpath v1.1.8 h1:PcL6bIX42Px5usSx6xRYw/wjB3wYGkj0MJ9MBzEKVgk= github.com/antchfx/xpath v1.1.8/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= +github.com/antchfx/xpath v1.2.3/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= +github.com/antchfx/xpath v1.2.4 h1:dW1HB/JxKvGtJ9WyVGJ0sIoEcqftV3SqIstujI+B9XY= +github.com/antchfx/xpath v1.2.4/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -21,13 +28,13 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI= github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA= github.com/gocolly/colly/v2 v2.1.0 h1:k0DuZkDoCsx51bKpRJNEmcxcp+W5N8ziuwGaSDuFoGs= github.com/gocolly/colly/v2 v2.1.0/go.mod h1:I2MuhsLjQ+Ex+IzK3afNS8/1qP3AedHOusRPcRdC5o0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -38,33 +45,42 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg= github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o= github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxTvN8n+Kvkn6TrbMyxQiuvKdEwFdR9vI= github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= +github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA= +github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/temoto/robotstxt v1.1.1 h1:Gh8RCs8ouX3hRSxxK7B1mO5RFByQ4CmJZDwgom++JaA= github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= +github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg= +github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -72,35 +88,70 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= @@ -115,7 +166,10 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/search.go b/search.go index ff3b263..deb8702 100644 --- a/search.go +++ b/search.go @@ -284,7 +284,7 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re } if opts[0].UserAgent == "" { - c.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" + c.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672 Safari/537.36" } else { c.UserAgent = opts[0].UserAgent } diff --git a/search_test.go b/search_test.go index 6412d07..f6b196a 100644 --- a/search_test.go +++ b/search_test.go @@ -6,7 +6,7 @@ import ( "context" "testing" - "github.com/rocketlaunchr/google-search" + googlesearch "github.com/chrisjoyce911/google-search" ) var ctx = context.Background() From 552a24ed329a8d75c226bc838ce7bf895fff7f8f Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 19:01:58 +1000 Subject: [PATCH 05/16] Updated test to not use packas as external lib --- search_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/search_test.go b/search_test.go index f6b196a..99b9f1a 100644 --- a/search_test.go +++ b/search_test.go @@ -1,12 +1,10 @@ // Copyright 2020-21 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved. -package googlesearch_test +package googlesearch import ( "context" "testing" - - googlesearch "github.com/chrisjoyce911/google-search" ) var ctx = context.Background() @@ -15,11 +13,11 @@ func TestSearch(t *testing.T) { q := "Hello World" - opts := googlesearch.SearchOptions{ + opts := SearchOptions{ Limit: 20, } - returnLinks, err := googlesearch.Search(ctx, q, opts) + returnLinks, err := Search(ctx, q, opts) if err != nil { t.Errorf("something went wrong: %v", err) return From e6cefd6ada41d6fa680aa01ea996e775264ece4b Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 19:34:56 +1000 Subject: [PATCH 06/16] Moved example to a test --- example/main.go | 13 ------------- example_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) delete mode 100644 example/main.go create mode 100644 example_test.go diff --git a/example/main.go b/example/main.go deleted file mode 100644 index 17e72fc..0000000 --- a/example/main.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import ( - "context" - "fmt" - - googlesearch "github.com/chrisjoyce911/google-search" -) - -func main() { - - fmt.Println(googlesearch.Search(context.Background(), "First Aid Course Australia Wide First Aid")) -} diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..cd50781 --- /dev/null +++ b/example_test.go @@ -0,0 +1,30 @@ +package googlesearch + +import ( + "context" + "fmt" + "strings" +) + +func ExampleSearch() { + + opt := SearchOptions{ + CountryCode: "au", + } + + serp, err := Search(context.Background(), "First Aid Course Australia Wide First Aid", opt) + + if err != nil { + fmt.Print(err.Error()) + } + + for _, resault := range serp { + if strings.Contains(resault.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 + +} From 87f0cd19408da424e734a561b4713603eae1baae Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 19:36:54 +1000 Subject: [PATCH 07/16] restored module name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 20fed7d..55cfa15 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/chrisjoyce911/google-search +module github.com/rocketlaunchr/google-search go 1.20 From 6b8d3ebbca76f6ea88100bb6933df6c5c79dc593 Mon Sep 17 00:00:00 2001 From: Kay Nelson Date: Wed, 17 May 2023 14:57:49 +0200 Subject: [PATCH 08/16] Update the default User-Agent --- search.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search.go b/search.go index deb8702..a759786 100644 --- a/search.go +++ b/search.go @@ -284,7 +284,7 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re } if opts[0].UserAgent == "" { - c.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672 Safari/537.36" + c.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" } else { c.UserAgent = opts[0].UserAgent } From 20e5149740c0b526dd56ee39141ad14b3f8bf859 Mon Sep 17 00:00:00 2001 From: miguelp Date: Sat, 8 Oct 2022 01:40:08 +0100 Subject: [PATCH 09/16] changed package name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 55cfa15..e5f6be5 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rocketlaunchr/google-search +module github.com/lookatitude/google-search go 1.20 From 42aab3d7fc6f7ddfbffcde9ee831dd45ec2930b3 Mon Sep 17 00:00:00 2001 From: miguelp Date: Sat, 8 Oct 2022 01:46:27 +0100 Subject: [PATCH 10/16] cahnged package name to be able to import from fork --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e5f6be5..55cfa15 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/lookatitude/google-search +module github.com/rocketlaunchr/google-search go 1.20 From f72b448bec456f1328919235917f0c9099c4ce2d Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 14:56:25 +1000 Subject: [PATCH 11/16] Updated go, useragent and added example --- example/main.go | 13 +++++++++++++ go.mod | 2 +- search.go | 1 - 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 example/main.go diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..17e72fc --- /dev/null +++ b/example/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "context" + "fmt" + + googlesearch "github.com/chrisjoyce911/google-search" +) + +func main() { + + fmt.Println(googlesearch.Search(context.Background(), "First Aid Course Australia Wide First Aid")) +} diff --git a/go.mod b/go.mod index 55cfa15..20fed7d 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rocketlaunchr/google-search +module github.com/chrisjoyce911/google-search go 1.20 diff --git a/search.go b/search.go index a759786..1a72aa7 100644 --- a/search.go +++ b/search.go @@ -285,7 +285,6 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re if opts[0].UserAgent == "" { c.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" - } else { c.UserAgent = opts[0].UserAgent } From a22732eeb67c4f8d73d0147c469baff8793031d0 Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 19:34:56 +1000 Subject: [PATCH 12/16] Moved example to a test --- example/main.go | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 example/main.go diff --git a/example/main.go b/example/main.go deleted file mode 100644 index 17e72fc..0000000 --- a/example/main.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import ( - "context" - "fmt" - - googlesearch "github.com/chrisjoyce911/google-search" -) - -func main() { - - fmt.Println(googlesearch.Search(context.Background(), "First Aid Course Australia Wide First Aid")) -} From 31583a67d04c2a87758b4a18e4249229af75d559 Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 19:36:54 +1000 Subject: [PATCH 13/16] restored module name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 20fed7d..55cfa15 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/chrisjoyce911/google-search +module github.com/rocketlaunchr/google-search go 1.20 From 8179baaa61ac5afb1751b70d0f699ee13d5ea10f Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Thu, 25 May 2023 20:34:28 +1000 Subject: [PATCH 14/16] Added Using a Fork to Readme --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 697ddc9..a10426e 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,15 @@ Also note, that if you call this function too quickly, Google detects that it is +## Using a Fork + +If you are wanting to use an active Fork you can replace it in your gomod.go by doing the following + +```bash +go get github.com/chrisjoyce911/google-search +go mod edit -replace github.com/rocketlaunchr/google-search=github.com/chrisjoyce911/google-search@master +go mod tidy +``` ## Credits From bcbf8ae1b3e8abbeadec471cff16e04cbb8af300 Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Fri, 26 May 2023 13:06:12 +1000 Subject: [PATCH 15/16] Fix optional UserAgent Added an example --- example_test.go | 30 ++++++++++++++++++++++++++++++ search.go | 4 +++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/example_test.go b/example_test.go index cd50781..5ec24c9 100644 --- a/example_test.go +++ b/example_test.go @@ -28,3 +28,33 @@ func ExampleSearch() { // 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", + } + + serp, err := Search(context.Background(), "First Aid Course Australia Wide First Aid", opt) + + if err != nil { + fmt.Print(err.Error()) + } + + for _, resault := range serp { + if strings.Contains(resault.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 + +} diff --git a/search.go b/search.go index 1a72aa7..2e509ef 100644 --- a/search.go +++ b/search.go @@ -31,6 +31,7 @@ type Result struct { } const stdGoogleBase = "https://www.google." +const defaultAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" // GoogleDomains represents localized Google homepages. The 2 letter country code is based on ISO 3166-1 alpha-2. // @@ -284,7 +285,8 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re } if opts[0].UserAgent == "" { - c.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" + c.UserAgent = defaultAgent + } else { c.UserAgent = opts[0].UserAgent } From dfdb3593e1e2388020736c362ba2bd21d4b6222e Mon Sep 17 00:00:00 2001 From: Chris Joyce Date: Sat, 27 May 2023 17:31:50 +1000 Subject: [PATCH 16/16] Pull request issues resolved * Remove contect from tests * Resorted package dependacy for TestSearch * Removed extra notes from README --- README.md | 9 --------- example_test.go | 15 ++++++++------- go.mod | 6 +----- go.sum | 3 +++ search_test.go | 12 ++++++------ 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index a10426e..697ddc9 100644 --- a/README.md +++ b/README.md @@ -88,15 +88,6 @@ Also note, that if you call this function too quickly, Google detects that it is -## Using a Fork - -If you are wanting to use an active Fork you can replace it in your gomod.go by doing the following - -```bash -go get github.com/chrisjoyce911/google-search -go mod edit -replace github.com/rocketlaunchr/google-search=github.com/chrisjoyce911/google-search@master -go mod tidy -``` ## Credits diff --git a/example_test.go b/example_test.go index 5ec24c9..8dad19f 100644 --- a/example_test.go +++ b/example_test.go @@ -1,7 +1,6 @@ package googlesearch import ( - "context" "fmt" "strings" ) @@ -12,14 +11,15 @@ func ExampleSearch() { CountryCode: "au", } - serp, err := Search(context.Background(), "First Aid Course Australia Wide First Aid", opt) + //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 _, resault := range serp { - if strings.Contains(resault.URL, "australiawidefirstaid.com.au") { + 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 } @@ -42,14 +42,15 @@ func ExampleUserAgent() { UserAgent: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36", } - serp, err := Search(context.Background(), "First Aid Course Australia Wide First Aid", opt) + //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 _, resault := range serp { - if strings.Contains(resault.URL, "australiawidefirstaid.com.au") { + 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 } diff --git a/go.mod b/go.mod index 55cfa15..b6afd61 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rocketlaunchr/google-search -go 1.20 +go 1.16 require ( github.com/gocolly/colly/v2 v2.1.0 @@ -13,14 +13,10 @@ require ( 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/gobwas/glob v0.2.3 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/kennygrant/sanitize v1.2.4 // 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 - golang.org/x/text v0.9.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.30.0 // indirect ) diff --git a/go.sum b/go.sum index 2655b8a..0c6ae2e 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,7 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI= github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA= github.com/gocolly/colly/v2 v2.1.0 h1:k0DuZkDoCsx51bKpRJNEmcxcp+W5N8ziuwGaSDuFoGs= github.com/gocolly/colly/v2 v2.1.0/go.mod h1:I2MuhsLjQ+Ex+IzK3afNS8/1qP3AedHOusRPcRdC5o0= @@ -119,11 +120,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/search_test.go b/search_test.go index 99b9f1a..f56a030 100644 --- a/search_test.go +++ b/search_test.go @@ -1,23 +1,23 @@ // Copyright 2020-21 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved. -package googlesearch +package googlesearch_test import ( - "context" "testing" -) -var ctx = context.Background() + googlesearch "github.com/rocketlaunchr/google-search" +) func TestSearch(t *testing.T) { q := "Hello World" - opts := SearchOptions{ + opts := googlesearch.SearchOptions{ Limit: 20, } - returnLinks, err := Search(ctx, q, opts) + //lint:ignore SA1012 ignore this bare essentials by passing nil for context and removing context package (despite not being idiomatic go). + returnLinks, err := googlesearch.Search(nil, q, opts) if err != nil { t.Errorf("something went wrong: %v", err) return