diff --git a/README.md b/README.md index 4ba2ac1..2dbd48c 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Also note, that if you call this function too quickly, Google detects that it is You can try the built-in [rate-limiter](https://godoc.org/github.com/rocketlaunchr/google-search#RateLimit).
- Further Details + HTTP STATUS CODE: 429 — Too Many Requests @@ -72,7 +72,6 @@ You can try the built-in [rate-limiter](https://godoc.org/github.com/rocketlaunc
- [HTTP STATUS CODE: 429 — Too Many Requests] About this page

Our systems have detected unusual traffic from your computer network. This page checks to see if it's really you sending the requests, and not a robot. Why did this happen?

diff --git a/limit.go b/limit.go index f91ad5e..0ea7ab8 100644 --- a/limit.go +++ b/limit.go @@ -1,6 +1,16 @@ package googlesearch -import "golang.org/x/time/rate" +import ( + "errors" + + "golang.org/x/time/rate" +) + +// ErrBlocked indicates that Google has detected that you were scraping and temporarily blocked you. +// The duration of the block is unspecified. +// +// See: https://github.com/rocketlaunchr/google-search#warning-warning +var ErrBlocked = errors.New("google block") // RateLimit sets a global limit to how many requests to Google Search can be made in a given time interval. // The default is unlimited (but obviously Google Search will block you temporarily if you do too many diff --git a/search.go b/search.go index 8f37b45..1a173df 100644 --- a/search.go +++ b/search.go @@ -340,6 +340,9 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re c.Visit(url) if rErr != nil { + if strings.Contains(rErr.Error(), "Too Many Requests") { + return nil, ErrBlocked + } return nil, rErr }