- update readme
- add ErrBlocked
This commit is contained in:
parent
90bd74a100
commit
3235dc50c9
@ -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).
|
You can try the built-in [rate-limiter](https://godoc.org/github.com/rocketlaunchr/google-search#RateLimit).
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Further Details</summary>
|
<summary>HTTP STATUS CODE: 429 — Too Many Requests</summary>
|
||||||
|
|
||||||
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
|
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
|
||||||
<foreignObject width="100" height="100">
|
<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;">
|
<div style="font-size:13px;">
|
||||||
[HTTP STATUS CODE: 429 — Too Many Requests]
|
|
||||||
<b>About this page</b><br><br>
|
<b>About this page</b><br><br>
|
||||||
|
|
||||||
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. <a href="#" onclick="document.getElementById('infoDiv').style.display='block';">Why did this happen?</a><br><br>
|
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. <a href="#" onclick="document.getElementById('infoDiv').style.display='block';">Why did this happen?</a><br><br>
|
||||||
|
12
limit.go
12
limit.go
@ -1,6 +1,16 @@
|
|||||||
package googlesearch
|
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.
|
// 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
|
// The default is unlimited (but obviously Google Search will block you temporarily if you do too many
|
||||||
|
@ -340,6 +340,9 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re
|
|||||||
c.Visit(url)
|
c.Visit(url)
|
||||||
|
|
||||||
if rErr != nil {
|
if rErr != nil {
|
||||||
|
if strings.Contains(rErr.Error(), "Too Many Requests") {
|
||||||
|
return nil, ErrBlocked
|
||||||
|
}
|
||||||
return nil, rErr
|
return nil, rErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user