gserp 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gserp-0.2.0/LICENSE +21 -0
- gserp-0.2.0/MANIFEST.in +1 -0
- gserp-0.2.0/PKG-INFO +497 -0
- gserp-0.2.0/README.md +465 -0
- gserp-0.2.0/pyproject.toml +74 -0
- gserp-0.2.0/setup.cfg +4 -0
- gserp-0.2.0/src/gserp/__init__.py +27 -0
- gserp-0.2.0/src/gserp/__main__.py +5 -0
- gserp-0.2.0/src/gserp/browser.py +485 -0
- gserp-0.2.0/src/gserp/classify.py +105 -0
- gserp-0.2.0/src/gserp/cli.py +497 -0
- gserp-0.2.0/src/gserp/doctor.py +155 -0
- gserp-0.2.0/src/gserp/engines.py +53 -0
- gserp-0.2.0/src/gserp/env.py +16 -0
- gserp-0.2.0/src/gserp/hybrid.py +580 -0
- gserp-0.2.0/src/gserp/links.py +358 -0
- gserp-0.2.0/src/gserp/mcp.py +195 -0
- gserp-0.2.0/src/gserp/output.py +151 -0
- gserp-0.2.0/src/gserp/parse.py +560 -0
- gserp-0.2.0/src/gserp/pool.py +202 -0
- gserp-0.2.0/src/gserp/proxy.py +194 -0
- gserp-0.2.0/src/gserp/quality.py +93 -0
- gserp-0.2.0/src/gserp/relay.py +306 -0
- gserp-0.2.0/src/gserp/scraper.py +1826 -0
- gserp-0.2.0/src/gserp/server.py +516 -0
- gserp-0.2.0/src/gserp/warmup.py +44 -0
- gserp-0.2.0/src/gserp.egg-info/PKG-INFO +497 -0
- gserp-0.2.0/src/gserp.egg-info/SOURCES.txt +47 -0
- gserp-0.2.0/src/gserp.egg-info/dependency_links.txt +1 -0
- gserp-0.2.0/src/gserp.egg-info/entry_points.txt +2 -0
- gserp-0.2.0/src/gserp.egg-info/requires.txt +17 -0
- gserp-0.2.0/src/gserp.egg-info/top_level.txt +1 -0
- gserp-0.2.0/tests/fakegoogle.py +96 -0
- gserp-0.2.0/tests/pages.py +149 -0
- gserp-0.2.0/tests/stdio_mcp_child.py +39 -0
- gserp-0.2.0/tests/test_browser_local.py +179 -0
- gserp-0.2.0/tests/test_classify.py +58 -0
- gserp-0.2.0/tests/test_cli_and_output.py +325 -0
- gserp-0.2.0/tests/test_engines_local.py +162 -0
- gserp-0.2.0/tests/test_env_and_legacy.py +92 -0
- gserp-0.2.0/tests/test_hybrid.py +516 -0
- gserp-0.2.0/tests/test_links.py +539 -0
- gserp-0.2.0/tests/test_parse.py +303 -0
- gserp-0.2.0/tests/test_pool.py +271 -0
- gserp-0.2.0/tests/test_proxy.py +178 -0
- gserp-0.2.0/tests/test_relay.py +247 -0
- gserp-0.2.0/tests/test_scraper.py +1805 -0
- gserp-0.2.0/tests/test_serve_and_mcp.py +734 -0
- gserp-0.2.0/tests/test_warmup.py +15 -0
gserp-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NodeMaven
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
gserp-0.2.0/MANIFEST.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include tests *.py
|
gserp-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gserp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Self-hosted Google SERP API: Google Search results as JSON from a real Chrome browser through your own residential proxy. HTTP API, CLI and MCP server.
|
|
5
|
+
Author: NodeMaven
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Source, https://github.com/nodemaven/gserp
|
|
8
|
+
Project-URL: Issues, https://github.com/nodemaven/gserp/issues
|
|
9
|
+
Project-URL: Benchmark, https://github.com/nodemaven/proxy-benchmark
|
|
10
|
+
Keywords: google,google-search,google-search-api,serp,serp-api,scraper,search,self-hosted,proxy,mcp,playwright,patchright
|
|
11
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: patchright==1.64.3
|
|
19
|
+
Requires-Dist: lxml>=5
|
|
20
|
+
Requires-Dist: curl_cffi==0.17.0
|
|
21
|
+
Provides-Extra: nodemaven
|
|
22
|
+
Requires-Dist: nodemaven>=0.1.5; extra == "nodemaven"
|
|
23
|
+
Provides-Extra: cloak
|
|
24
|
+
Requires-Dist: cloakbrowser>=0.5; extra == "cloak"
|
|
25
|
+
Provides-Extra: all
|
|
26
|
+
Requires-Dist: nodemaven>=0.1.5; extra == "all"
|
|
27
|
+
Requires-Dist: cloakbrowser>=0.5; extra == "all"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
<div align="center">
|
|
34
|
+
|
|
35
|
+
<img src="https://raw.githubusercontent.com/nodemaven/gserp/main/assets/banner.png" alt="gserp">
|
|
36
|
+
|
|
37
|
+
<h1>gserp</h1>
|
|
38
|
+
|
|
39
|
+
<p><b>Self-hosted SERP API alternative: Google search results from a real Chrome browser and your own residential proxy.</b></p>
|
|
40
|
+
|
|
41
|
+
<p>Formerly <code>google-browser-scraper</code>: that package now installs gserp, and the old command, import and <code>GBS_*</code> variables keep working.</p>
|
|
42
|
+
|
|
43
|
+
[](https://pypi.org/project/gserp/)
|
|
44
|
+
[](https://pypi.org/project/gserp/)
|
|
45
|
+
[](https://github.com/nodemaven/gserp/actions/workflows/ci.yml)
|
|
46
|
+
[](https://opensource.org/licenses/MIT)
|
|
47
|
+
[](https://github.com/nodemaven/gserp/pkgs/container/gserp)
|
|
48
|
+
[](https://dashboard.nodemaven.com/accounts/signup/?utm_source=github&utm_medium=readme&utm_campaign=google_browser_scraper&utm_content=promo_badge)
|
|
49
|
+
|
|
50
|
+
<a href="https://devhunt.org/tool/google-search-scraper"><img src="https://devhunt.org/badge/google-search-scraper.svg" alt="gserp on DevHunt" height="44"></a>
|
|
51
|
+
|
|
52
|
+
[Quickstart](#quickstart) · [Output](#what-you-get) · [Poisoned results](#poisoned-results-protection) · [HTTP API](#run-it-as-an-api) · [MCP](#use-it-from-an-ai-agent-mcp) · [Docker](#docker) · [How it works](#how-it-works) · [Options](#options)
|
|
53
|
+
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<br>
|
|
57
|
+
|
|
58
|
+
<p align="center">
|
|
59
|
+
<img src="https://raw.githubusercontent.com/nodemaven/gserp/main/assets/demo.gif" alt="A real Chrome window showing Google results next to the JSON the scraper produced for them" width="900">
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
<div align="center">
|
|
63
|
+
|
|
64
|
+
| ✅ **100%** | 📉 **0.4 MB** | ⚡ **1.4 s** |
|
|
65
|
+
|:---:|:---:|:---:|
|
|
66
|
+
| success rate | per search | per search on a warm proxy IP |
|
|
67
|
+
|
|
68
|
+
<sub>Latest version benchmarks (v0.1)</sub>
|
|
69
|
+
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
Scrape Google search results (SERP) with a real Chrome browser and your own
|
|
73
|
+
residential proxy, and get clean JSON back. Use it as a CLI, a Python library,
|
|
74
|
+
a local HTTP API, or an MCP server that gives AI agents live Google search.
|
|
75
|
+
|
|
76
|
+
Plain HTTP is no longer a reliable way to scrape Google, and a fresh browser on a
|
|
77
|
+
fresh proxy IP is refused quickly. So the scraper warms its first sticky proxy
|
|
78
|
+
session with ordinary browsing and starts later ones from the cookies Google
|
|
79
|
+
already accepts, lets the browser pass Google's checks, and then fetches results
|
|
80
|
+
pages directly over HTTPS with the browser's own cookies. Captchas and
|
|
81
|
+
blocks are reported as such, never as "no results".
|
|
82
|
+
|
|
83
|
+
## Features
|
|
84
|
+
|
|
85
|
+
<table>
|
|
86
|
+
<tr>
|
|
87
|
+
<td width="50%" valign="top">
|
|
88
|
+
|
|
89
|
+
⚡ **Hybrid mode**<br>
|
|
90
|
+
Results pages over HTTPS between Google's checks: a fraction of a browser's traffic and time. The browser takes over by itself when needed.
|
|
91
|
+
|
|
92
|
+
</td>
|
|
93
|
+
<td width="50%" valign="top">
|
|
94
|
+
|
|
95
|
+
🛡️ **Poisoned results protection**<br>
|
|
96
|
+
Pages of results for some other query are caught: the proxy IP serving them is dropped within a few pages and the query is asked again on a fresh one.
|
|
97
|
+
|
|
98
|
+
</td>
|
|
99
|
+
</tr>
|
|
100
|
+
<tr>
|
|
101
|
+
<td valign="top">
|
|
102
|
+
|
|
103
|
+
🌐 **Real browser**<br>
|
|
104
|
+
Real Chrome via Patchright, warmed up once and then carrying the cookies Google already trusts to every new identity, so Google's checks pass.
|
|
105
|
+
|
|
106
|
+
</td>
|
|
107
|
+
<td valign="top">
|
|
108
|
+
|
|
109
|
+
🧩 **SERP API-style JSON**<br>
|
|
110
|
+
`organic_results`, `ads`, `related_questions`, `related_searches`, `pagination`, `ai_overview`, `local_results`.
|
|
111
|
+
|
|
112
|
+
</td>
|
|
113
|
+
</tr>
|
|
114
|
+
<tr>
|
|
115
|
+
<td valign="top">
|
|
116
|
+
|
|
117
|
+
🔌 **Bring your own proxy**<br>
|
|
118
|
+
Any residential proxy with sticky sessions, built-in [NodeMaven](https://nodemaven.com/?utm_source=github&utm_medium=readme&utm_campaign=google_browser_scraper&utm_content=features) support.
|
|
119
|
+
|
|
120
|
+
</td>
|
|
121
|
+
<td valign="top">
|
|
122
|
+
|
|
123
|
+
🚦 **Honest failures**<br>
|
|
124
|
+
Captchas and blocks come back labeled, not as empty results.
|
|
125
|
+
|
|
126
|
+
</td>
|
|
127
|
+
</tr>
|
|
128
|
+
<tr>
|
|
129
|
+
<td valign="top">
|
|
130
|
+
|
|
131
|
+
🤖 **For AI agents**<br>
|
|
132
|
+
An MCP server that gives agents live Google search, with the AI Overview and map places.
|
|
133
|
+
|
|
134
|
+
</td>
|
|
135
|
+
<td valign="top">
|
|
136
|
+
|
|
137
|
+
🐳 **Run it your way**<br>
|
|
138
|
+
CLI, Python library, HTTP API, MCP server or Docker image. Traffic and cost per 1000 pages in every run summary.
|
|
139
|
+
|
|
140
|
+
</td>
|
|
141
|
+
</tr>
|
|
142
|
+
</table>
|
|
143
|
+
|
|
144
|
+
## Use cases
|
|
145
|
+
|
|
146
|
+
- SEO rank tracking and SERP monitoring for your own keywords
|
|
147
|
+
- Keyword and competitor research from live Google results
|
|
148
|
+
- Web search for AI agents and LLM apps through MCP
|
|
149
|
+
- A self-hosted alternative to paid Google search APIs when you already pay for proxies
|
|
150
|
+
|
|
151
|
+
## Install
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pip install gserp
|
|
155
|
+
patchright install chromium
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Quickstart
|
|
159
|
+
|
|
160
|
+
> [!NOTE]
|
|
161
|
+
> You need a residential proxy with **sticky sessions**. Put `{session}` where
|
|
162
|
+
> your provider expects a session id in the username.
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
gserp search "best running shoes" \
|
|
166
|
+
--proxy "http://USER-session-{session}:PASS@gate.example.com:7000" \
|
|
167
|
+
-o results.jsonl
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The first query takes a few minutes while the first proxy IP warms up; later
|
|
171
|
+
queries take seconds, and new proxy IPs start from its cookies. Every run ends with a summary of pages served and
|
|
172
|
+
traffic used.
|
|
173
|
+
|
|
174
|
+
### With NodeMaven
|
|
175
|
+
|
|
176
|
+
The session id is handled for you and the credentials come from the environment:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
pip install "gserp[nodemaven]"
|
|
180
|
+
export NODEMAVEN_LOGIN=... NODEMAVEN_PASSWORD=...
|
|
181
|
+
gserp search -f queries.txt --nodemaven --country us -o results.jsonl
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
> [!TIP]
|
|
185
|
+
> 🎁 **2 GB of free traffic.** No NodeMaven account yet? [Sign up](https://dashboard.nodemaven.com/accounts/signup/?utm_source=github&utm_medium=readme&utm_campaign=google_browser_scraper&utm_content=signup_promo) and enter the code **GOOGLENM**. Once per account.
|
|
186
|
+
|
|
187
|
+
<details>
|
|
188
|
+
<summary><b>Cap a run's traffic with a demo sub-user</b></summary>
|
|
189
|
+
|
|
190
|
+
<br>
|
|
191
|
+
|
|
192
|
+
`--nodemaven-demo` creates a sub-user with a traffic limit from your dashboard API
|
|
193
|
+
key, shares it across workers, and deletes it when the run ends (`--keep-subuser`
|
|
194
|
+
keeps it). The account needs sub-users enabled. A fresh warm-up alone uses about
|
|
195
|
+
60 MB, so keep the cap well above that:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
export NODEMAVEN_API_KEY=...
|
|
199
|
+
gserp search -f queries.txt --nodemaven-demo --traffic-limit-mb 300 -o results.jsonl
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
</details>
|
|
203
|
+
|
|
204
|
+
<details>
|
|
205
|
+
<summary><b>Try it without a proxy</b></summary>
|
|
206
|
+
|
|
207
|
+
<br>
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
gserp search "best running shoes" --no-proxy
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Google then sees one address for every query, so it starts answering with
|
|
214
|
+
captchas sooner than it would across a pool of proxy IPs. Those pages come back as
|
|
215
|
+
`captcha` in `page_verdict`, not as empty results.
|
|
216
|
+
|
|
217
|
+
</details>
|
|
218
|
+
|
|
219
|
+
### From Python
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from gserp import ProxyTemplate, Scraper, Settings
|
|
223
|
+
|
|
224
|
+
proxy = ProxyTemplate("http://USER-session-{session}:PASS@gate.example.com:7000")
|
|
225
|
+
for page in Scraper(proxy, Settings(pages=2)).run(["best running shoes"]):
|
|
226
|
+
for result in page.get("organic_results", []):
|
|
227
|
+
print(result["position"], result["title"], result["link"])
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## What you get
|
|
231
|
+
|
|
232
|
+
One JSON object per results page:
|
|
233
|
+
|
|
234
|
+
```json
|
|
235
|
+
{
|
|
236
|
+
"search_metadata": {"status": "Success", "page_verdict": "ok", "fetched_with": "http"},
|
|
237
|
+
"search_parameters": {"engine": "google", "q": "best running shoes", "page": 1},
|
|
238
|
+
"organic_results": [
|
|
239
|
+
{"position": 1, "title": "...", "link": "https://...", "snippet": "..."}
|
|
240
|
+
],
|
|
241
|
+
"related_questions": [{"question": "..."}],
|
|
242
|
+
"ai_overview": {"text": "..."},
|
|
243
|
+
"exit": {"session": "...", "queries_on_exit": 1, "bytes": "..."}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The field names are the ones common to SERP APIs, so simple consumers can often
|
|
248
|
+
switch with minimal mapping.
|
|
249
|
+
|
|
250
|
+
<details>
|
|
251
|
+
<summary><b>All fields</b></summary>
|
|
252
|
+
|
|
253
|
+
<br>
|
|
254
|
+
|
|
255
|
+
- `organic_results`, `ads`, `related_questions`, `related_searches`, `pagination`, `search_metadata`
|
|
256
|
+
- `ai_overview`: the text of Google's AI Overview when the page shows one (pages in English, `--hl en`, the default)
|
|
257
|
+
- `local_results`: the places of the map pack on local queries (name, rating, reviews, type, address, phone, opening hours)
|
|
258
|
+
- `exit`: which proxy IP (sticky session) answered and how many bytes the page cost
|
|
259
|
+
- `search_metadata.fetched_with`: `http` or `browser`
|
|
260
|
+
- `search_metadata.timings`: seconds per step (`http` for a page fetched over HTTP; `type`, `load`, `ready` and `read` for one the browser rendered; `parse`; `links`, which overlaps the next query)
|
|
261
|
+
- A query that failed is a record too, with an `error`
|
|
262
|
+
|
|
263
|
+
Knowledge panels, shopping, images and other special blocks are not parsed.
|
|
264
|
+
`--format csv` writes the organic results as a table, and `--price-per-gb` adds
|
|
265
|
+
the cost per 1000 pages to the summary.
|
|
266
|
+
|
|
267
|
+
</details>
|
|
268
|
+
|
|
269
|
+
## Poisoned results protection
|
|
270
|
+
|
|
271
|
+
Google does not always block a scraper. Sometimes it answers with a normal-looking
|
|
272
|
+
results page for a different query: no captcha, no error, just wrong data that
|
|
273
|
+
slips into your pipeline unnoticed.
|
|
274
|
+
|
|
275
|
+
The scraper checks results pages against the queries it asked. When a proxy IP
|
|
276
|
+
starts returning unrelated results, it is dropped within a few pages and the query
|
|
277
|
+
is asked again on a fresh one.
|
|
278
|
+
|
|
279
|
+
- No extra requests, no extra traffic: the check runs on the page already downloaded
|
|
280
|
+
- On by default
|
|
281
|
+
|
|
282
|
+
## Run it as an API
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
gserp serve --nodemaven --country us --prewarm
|
|
286
|
+
curl "http://127.0.0.1:8000/search.json?q=best+running+shoes"
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
- Same record format as above
|
|
290
|
+
- `hl` (language) and `gl` (country) per request: `/search.json?q=...&hl=de&gl=at`
|
|
291
|
+
- `--prewarm` finds a proxy IP Google serves at startup, so the first request does not wait for a warm-up; `/health` answers 503 `warming` until then
|
|
292
|
+
- Results pages are read one at a time on one held proxy IP; a page's links resolve in the background, so the next request starts while the last one waits for its links
|
|
293
|
+
- `links=N` resolves the links of the first N organic results only (`0`: none)
|
|
294
|
+
- `links_wait=S` answers after S seconds with the links resolved by then; links still being resolved are `null` and counted in `search_metadata.links_pending`
|
|
295
|
+
- `async=true` answers at once with `search_metadata.id`; `GET /searches/<id>.json` answers `"status": "Processing"` until the search and its links are done, then the record. The newest 500 searches are kept there, each for up to an hour; up to 50 async searches wait for the browser at once, more are answered 429
|
|
296
|
+
- Set `GSERP_API_KEY` to require a key; without one the server only listens on localhost
|
|
297
|
+
|
|
298
|
+
## Use it from an AI agent (MCP)
|
|
299
|
+
|
|
300
|
+
```json
|
|
301
|
+
{
|
|
302
|
+
"mcpServers": {
|
|
303
|
+
"google-search": {
|
|
304
|
+
"command": "gserp",
|
|
305
|
+
"args": ["mcp", "--nodemaven", "--country", "us", "--prewarm"],
|
|
306
|
+
"env": {"NODEMAVEN_LOGIN": "...", "NODEMAVEN_PASSWORD": "..."}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
One tool, `google_search(query, pages, hl, gl)`. It returns the organic results,
|
|
313
|
+
"People also ask", related searches, and the AI Overview and map places when
|
|
314
|
+
Google shows them.
|
|
315
|
+
|
|
316
|
+
## Docker
|
|
317
|
+
|
|
318
|
+
A ready image is published to GitHub Container Registry with every release:
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
docker run --rm ghcr.io/nodemaven/gserp doctor
|
|
322
|
+
docker run --rm -p 8000:8000 -e GSERP_API_KEY=change-me \
|
|
323
|
+
-e GSERP_PROXY='http://USER-session-{session}:PASS@gate.example.com:7000' \
|
|
324
|
+
ghcr.io/nodemaven/gserp serve --host 0.0.0.0
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
To build it yourself: `docker build -t gserp .`
|
|
328
|
+
|
|
329
|
+
## How it works
|
|
330
|
+
|
|
331
|
+
1. **New identity:** a sticky proxy session and a fresh browser profile.
|
|
332
|
+
2. **Warm-up:** the first proxy IP opens a few ordinary pages, staying on each
|
|
333
|
+
for 20-45 seconds. Later ones start from the Google cookies of a served proxy
|
|
334
|
+
IP and are warmed up only when no such set is accepted.
|
|
335
|
+
3. **Search:** the first query on a proxy IP goes through the browser. Once Google
|
|
336
|
+
serves it, the next pages come over HTTPS with the browser's cookies, until
|
|
337
|
+
Google asks for its check again.
|
|
338
|
+
4. **Check before parsing:** a captcha or a block is reported as one, never
|
|
339
|
+
parsed as an empty result.
|
|
340
|
+
5. **Keep or drop:** a proxy IP Google answers is reused; one it refuses is dropped
|
|
341
|
+
and the query retried on a new one. If one proxy IP after another is refused, the run
|
|
342
|
+
stops instead of spending more traffic.
|
|
343
|
+
|
|
344
|
+
<details>
|
|
345
|
+
<summary><b>More detail: HTTP between checks, holding proxy IPs, copied cookies, result links, traffic</b></summary>
|
|
346
|
+
|
|
347
|
+
<br>
|
|
348
|
+
|
|
349
|
+
**HTTP between checks.** After the browser passes Google's check, results pages
|
|
350
|
+
are fetched over HTTPS with the browser's own headers and cookies. If that stops
|
|
351
|
+
working, the scraper goes back to the browser on its own. `--no-hybrid` uses the
|
|
352
|
+
browser for every page.
|
|
353
|
+
|
|
354
|
+
**Unrelated results.** A proxy IP that starts returning results unrelated to the
|
|
355
|
+
queries is dropped, and the query is asked again on a new one.
|
|
356
|
+
|
|
357
|
+
**Holding proxy IPs.** A served proxy IP is kept for up to 300 queries. Every new one
|
|
358
|
+
pays for a browser check, and for a warm-up when no cookie set is accepted, so a
|
|
359
|
+
short cap mostly buys more of that traffic. Every 50
|
|
360
|
+
results pages it renders, the browser is restarted on the same profile and proxy IP, which keeps
|
|
361
|
+
its memory from growing over a long hold. A browser error on a search is retried
|
|
362
|
+
once on the same proxy IP before it is dropped; a network error, running out of
|
|
363
|
+
memory or a crashed browser drops it at once.
|
|
364
|
+
|
|
365
|
+
**Copying cookies.** With `--renew-cookies 0`, the command line copies the
|
|
366
|
+
cookies of the first proxy IP Google serves and starts new proxy IPs from that
|
|
367
|
+
copy, on new sticky sessions, instead of warming each one; all workers share
|
|
368
|
+
the copy. Google's acceptance follows the cookies more than the address, so a
|
|
369
|
+
copy usually starts out served and costs a few MB instead of a full warm-up. A
|
|
370
|
+
copy waits 40-60 seconds after its browser starts before the first search.
|
|
371
|
+
|
|
372
|
+
**Copying the cache.** Pages get cheaper as a proxy IP is held, because the
|
|
373
|
+
browser cache fills with Google's shared scripts and images. Copies carry that
|
|
374
|
+
cache too, so a new proxy IP starts with cheap pages, and the copy is refreshed
|
|
375
|
+
from the held one at each browser restart, when its cache is warm. If two
|
|
376
|
+
copies carrying the cache are refused on their first search, the rest of the
|
|
377
|
+
run copies cookies only (`--no-clone-cache` does that from the start).
|
|
378
|
+
|
|
379
|
+
**Starting from saved cookies.** `--cookies FILE` gives every new proxy IP the
|
|
380
|
+
Google cookies of a browser Google already serves, so it skips the warm-up; the
|
|
381
|
+
file can come from another machine. `--renew-cookies N` replaces that set with
|
|
382
|
+
the cookies of a served proxy IP every N queries, so it stays fresh, and without
|
|
383
|
+
`--cookies` it ends the warm-ups after the first renewal. It is on by default,
|
|
384
|
+
every 25 queries, so a run warms up its first proxy IP and rarely another;
|
|
385
|
+
`--renew-cookies 0` goes back to copies of the first served profile.
|
|
386
|
+
`--cookies-out DIR` saves each renewed set for the next run, readable by its
|
|
387
|
+
owner only. If every set is refused in turn, new proxy IPs are warmed up again,
|
|
388
|
+
and with `--renew-cookies` the next renewal brings the sets back. A file is a
|
|
389
|
+
JSON list of Playwright cookie records, or an object with that list under
|
|
390
|
+
`"cookies"`, and must hold Google's `NID` cookie.
|
|
391
|
+
|
|
392
|
+
**Result links.** Google wraps result links in encrypted `/goto` redirects.
|
|
393
|
+
Each one is resolved with a small request on the proxy IP the page came from,
|
|
394
|
+
with that page's cookies, in the background while the next query runs; a link
|
|
395
|
+
left over is tried through a separate short-lived proxy session. Google answers
|
|
396
|
+
only a few links of a page at once and holds the rest on a "Verifying your
|
|
397
|
+
request" page; a link held for up to 30 seconds is asked again when the wait is
|
|
398
|
+
over, twice at most and within 45 seconds a page, so a page's links can take up
|
|
399
|
+
to 45 seconds while the queries carry on.
|
|
400
|
+
Records still come out in the order each browser searched them.
|
|
401
|
+
|
|
402
|
+
**Traffic.** Everything goes through a small local relay that counts bytes per
|
|
403
|
+
host and blocks a large model download Chrome otherwise makes on every fresh
|
|
404
|
+
profile.
|
|
405
|
+
|
|
406
|
+
</details>
|
|
407
|
+
|
|
408
|
+
The defaults come from measurements in
|
|
409
|
+
[proxy-benchmark](https://github.com/nodemaven/proxy-benchmark).
|
|
410
|
+
|
|
411
|
+
## Options
|
|
412
|
+
|
|
413
|
+
<details>
|
|
414
|
+
<summary><b>All search options</b></summary>
|
|
415
|
+
|
|
416
|
+
<br>
|
|
417
|
+
|
|
418
|
+
| Option | Default | What it does |
|
|
419
|
+
|---|---|---|
|
|
420
|
+
| `--workers N` | 1 | Search on N proxy IPs at once, one browser each, from one list of queries |
|
|
421
|
+
| `--max-per-exit N` | 300 | Queries before a served proxy IP is retired |
|
|
422
|
+
| `--restart-every N` | 50 | Results pages the browser rendered before it restarts on the same profile and proxy IP; `0` never |
|
|
423
|
+
| `--no-hybrid` | | Fetch every results page in the browser instead of over HTTP between Google's checks |
|
|
424
|
+
| `--hl`, `--gl` | `en`, unset | Language and country of the results |
|
|
425
|
+
| `--clone N` | 10 | With `--renew-cookies 0`: new proxy IPs started from copied cookies; `0` turns copying off |
|
|
426
|
+
| `--clone-max-age` | 180 | Minutes copied cookies stay in use |
|
|
427
|
+
| `--clone-refusals N` | 1 | Copies refused in a row on their first query that end the copying |
|
|
428
|
+
| `--no-clone-cache` | | Copies carry cookies only, not the browser cache |
|
|
429
|
+
| `--cookies FILE` | | Start every new proxy IP from the Google cookies in FILE instead of a warm-up; repeat for more files, the next one taking over after two proxy IPs in a row are refused on their first query, and warm-ups again once every file has been refused that way. Turns `--clone` off |
|
|
430
|
+
| `--renew-cookies N` | 25 | Every N served queries, a proxy IP's Google cookies become the set new proxy IPs start from; `0` turns it off and brings back `--clone` |
|
|
431
|
+
| `--cookies-out DIR` | | Write each renewed cookie set to DIR, for the next run's `--cookies` |
|
|
432
|
+
| `--warmup` | `L3` | Pages a fresh proxy IP opens before its first query: `L3`, `light` (without Google Trends: much less traffic, served on the first query less often), `L2`, `L1`, `off` |
|
|
433
|
+
| `--spare N` | 0 | Proxy IPs warmed in the background so a retired one is replaced at once; each costs a warm-up |
|
|
434
|
+
| `--direct` | `all` | Open results pages directly: `all`, `follow-ups` (all but the first query on each proxy IP), `none` |
|
|
435
|
+
| `--input` | `type` | How a query goes into the search box: `type`, `insert`, `words` |
|
|
436
|
+
| `--gap LOW,HIGH` | 2,5 | Seconds between queries on one proxy IP |
|
|
437
|
+
| `--pages N` | 1 | Result pages per query |
|
|
438
|
+
| `--format` | `jsonl` | `jsonl` or `csv` |
|
|
439
|
+
| `--price-per-gb` | | Your proxy price, to print the cost per 1000 pages |
|
|
440
|
+
| `--no-resolve-links` | | Keep result links as Google `/goto` redirects |
|
|
441
|
+
| `--save-html DIR` | | Keep every page's HTML, gzipped |
|
|
442
|
+
|
|
443
|
+
`gserp search --help` lists the rest.
|
|
444
|
+
|
|
445
|
+
</details>
|
|
446
|
+
|
|
447
|
+
## Proxies
|
|
448
|
+
|
|
449
|
+
Any provider with sticky sessions works through `--proxy` and a `{session}`
|
|
450
|
+
placeholder. A proxy without one is accepted with a warning: if the proxy IP changes
|
|
451
|
+
on every request, warming it does nothing. SOCKS5 needs an IP-whitelisted
|
|
452
|
+
endpoint, because Chrome cannot send a SOCKS5 username and password.
|
|
453
|
+
|
|
454
|
+
## Check your machine
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
gserp doctor
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
Starts the browser on a blank page, sends nothing, and reports what a website
|
|
461
|
+
would see: whether the browser looks headless, whether WebGL works, the screen
|
|
462
|
+
size. Google answers some machines much less than others, so run this first.
|
|
463
|
+
|
|
464
|
+
## What this is not
|
|
465
|
+
|
|
466
|
+
Not a free Google Search API, and not a guarantee that every proxy IP will
|
|
467
|
+
work. It is a browser-based collector that makes failures explicit, drops proxy IPs
|
|
468
|
+
Google refuses, and tells you what each page cost.
|
|
469
|
+
|
|
470
|
+
## Status
|
|
471
|
+
|
|
472
|
+
Early. The `cloak` engine (`--engine cloak`) is experimental; `patchright` is
|
|
473
|
+
the default.
|
|
474
|
+
|
|
475
|
+
Google changes its pages often. If results come back empty or wrong, run with
|
|
476
|
+
`--save-html DIR` and open an issue with what you see.
|
|
477
|
+
|
|
478
|
+
You are responsible for using this within Google's terms and the law where you
|
|
479
|
+
run it.
|
|
480
|
+
|
|
481
|
+
## Adding an engine
|
|
482
|
+
|
|
483
|
+
An engine joins this tool only after it has been measured on
|
|
484
|
+
[proxy-benchmark](https://github.com/nodemaven/proxy-benchmark). Add it there
|
|
485
|
+
and run the warm-up ladder against Google:
|
|
486
|
+
|
|
487
|
+
```bash
|
|
488
|
+
python scripts/run_ladder.py --engines your-engine
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Then open a pull request here with the run file. The ladder runs identities
|
|
492
|
+
with and without the warm-up in the same hours, so the result shows whether the
|
|
493
|
+
engine actually gets served, not whether it got lucky once.
|
|
494
|
+
|
|
495
|
+
## License
|
|
496
|
+
|
|
497
|
+
[MIT](https://github.com/nodemaven/gserp/blob/main/LICENSE)
|