- update readme

- add ErrBlocked
This commit is contained in:
rocketlaunchr-cto 2021-01-13 16:57:47 +11:00
parent 90bd74a100
commit 3235dc50c9
3 changed files with 15 additions and 3 deletions

View File

@ -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).
<details>
<summary>Further Details</summary>
<summary>HTTP STATUS CODE: 429 &mdash; Too Many Requests</summary>
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<foreignObject width="100" height="100">
@ -72,7 +72,6 @@ You can try the built-in [rate-limiter](https://godoc.org/github.com/rocketlaunc
<div style="font-size:13px;">
[HTTP STATUS CODE: 429 &mdash; Too Many Requests]
<b>About this page</b><br><br>
Our systems have detected unusual traffic from your computer network. This page checks to see if it&#39;s really you sending the requests, and not a robot. <a href="#" onclick="document.getElementById('infoDiv').style.display='block';">Why did this happen?</a><br><br>

View File

@ -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

View File

@ -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
}