its-a-me-chrome 0.1.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.
- its_a_me_chrome-0.1.0/LICENSE +21 -0
- its_a_me_chrome-0.1.0/PKG-INFO +225 -0
- its_a_me_chrome-0.1.0/README.md +197 -0
- its_a_me_chrome-0.1.0/pyproject.toml +47 -0
- its_a_me_chrome-0.1.0/src/its_a_me_chrome/__init__.py +110 -0
- its_a_me_chrome-0.1.0/src/its_a_me_chrome/_snapshots.py +129 -0
- its_a_me_chrome-0.1.0/src/its_a_me_chrome/client.py +670 -0
- its_a_me_chrome-0.1.0/src/its_a_me_chrome/profile.py +283 -0
- its_a_me_chrome-0.1.0/src/its_a_me_chrome/py.typed +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bertrand Fan
|
|
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.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: its-a-me-chrome
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Download files, retrieve pages and call APIs with a real-Chrome network fingerprint
|
|
5
|
+
Keywords: chrome,fingerprint,tls,ja3,http2,curl-cffi,impersonate,scraping
|
|
6
|
+
Author: Bertrand Fan
|
|
7
|
+
Author-email: Bertrand Fan <bert@bert.org>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Dist: curl-cffi>=0.17.0
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Project-URL: Homepage, https://github.com/bertrandom/its-a-me-chrome
|
|
25
|
+
Project-URL: Issues, https://github.com/bertrandom/its-a-me-chrome/issues
|
|
26
|
+
Project-URL: Repository, https://github.com/bertrandom/its-a-me-chrome
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# its-a-me-chrome
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<img src="https://raw.githubusercontent.com/bertrandom/its-a-me-chrome/main/assets/chrome.jpg" alt="A cartoon Chrome logo in a red cap and overalls, holding a wrench, says "It's-a me, Chrome!" in a pixel-art desert with a T-rex and pterodactyls" width="830">
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
Fetch URLs — download files, load pages, call APIs — with the network
|
|
36
|
+
fingerprint of a **real Chrome browser**.
|
|
37
|
+
|
|
38
|
+
`its-a-me-chrome` wraps [`curl_cffi`](https://github.com/lexiforest/curl_cffi)
|
|
39
|
+
(curl-impersonate) and reproduces:
|
|
40
|
+
|
|
41
|
+
* the **TLS ClientHello / JA3 / JA4** and **HTTP/2** fingerprint of Chrome
|
|
42
|
+
(`chrome152`, verified to match Chrome 158);
|
|
43
|
+
* the real Chrome `User-Agent`;
|
|
44
|
+
* Chrome's exact header set **and header order**;
|
|
45
|
+
* the `priority: u=N, i` header and the matching HTTP/2 `PRIORITY` weight.
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
uv add its-a-me-chrome # from a git/path source
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Quick start
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import its_a_me_chrome
|
|
57
|
+
|
|
58
|
+
# Download a file (streamed to disk, written atomically)
|
|
59
|
+
result = its_a_me_chrome.download("https://example.com/cat.jpg", "cat.jpg")
|
|
60
|
+
print(result.path, result.size)
|
|
61
|
+
|
|
62
|
+
# Load a page as a top-level navigation would
|
|
63
|
+
page = its_a_me_chrome.get("https://example.com", context="document")
|
|
64
|
+
print(page.text[:200])
|
|
65
|
+
|
|
66
|
+
# Call a JSON API
|
|
67
|
+
data = its_a_me_chrome.post("https://api.example.com/search",
|
|
68
|
+
json={"q": "cats"},
|
|
69
|
+
headers={"x-api-key": token}).json()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Reusing a session
|
|
73
|
+
|
|
74
|
+
A `Client` keeps connections and cookies between requests, like one browser
|
|
75
|
+
tab. Defaults you pass to it apply to every call and can be overridden per
|
|
76
|
+
call.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
with its_a_me_chrome.Client(referer="https://example.com/") as client:
|
|
80
|
+
client.download(url1, "a.jpg")
|
|
81
|
+
client.download(url2, "downloads/") # filename from server or URL
|
|
82
|
+
body = client.fetch(url3) # bytes, nothing written
|
|
83
|
+
data = client.get(api_url, params={"page": 2}).json()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Errors
|
|
87
|
+
|
|
88
|
+
All errors derive from `its_a_me_chrome.ItsAMeChromeError`:
|
|
89
|
+
|
|
90
|
+
| exception | when |
|
|
91
|
+
|---------------|-------------------------------------------------------------|
|
|
92
|
+
| `RequestError`| DNS, TLS, connection failures |
|
|
93
|
+
| `Timeout` | the request took longer than `timeout` (a `RequestError`) |
|
|
94
|
+
| `HTTPError` | non-2xx status; `.status_code`, `.url`, and `.response` |
|
|
95
|
+
|
|
96
|
+
Non-2xx responses raise by default. Pass `raise_for_status=False` to get
|
|
97
|
+
the response back instead, then check `.ok`. For `request`/`get`/..., the
|
|
98
|
+
error carries the full response, so the error body is not lost:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
try:
|
|
102
|
+
its_a_me_chrome.get(url)
|
|
103
|
+
except its_a_me_chrome.HTTPError as err:
|
|
104
|
+
print(err.status_code, err.response.text)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`download()` raises `FileExistsError` **before sending anything** if the
|
|
108
|
+
target file exists, unless you pass `overwrite=True`.
|
|
109
|
+
|
|
110
|
+
## Request contexts
|
|
111
|
+
|
|
112
|
+
`context=` sets the `Sec-Fetch-*` / `Accept` headers and the priority to match
|
|
113
|
+
how Chrome tags each resource type:
|
|
114
|
+
|
|
115
|
+
| context | `Sec-Fetch-Dest` | `priority` | default for |
|
|
116
|
+
|------------|------------------|------------|-------------------------------------|
|
|
117
|
+
| `image` | `image` | `u=2, i` | `download()`, `fetch()` |
|
|
118
|
+
| `document` | `document` | `u=0, i` | — (use for HTML pages) |
|
|
119
|
+
| `script` | `script` | `u=2, i` | |
|
|
120
|
+
| `style` | `style` | `u=2, i` | |
|
|
121
|
+
| `font` | `font` | `u=3, i` | |
|
|
122
|
+
| `fetch` | `empty` | `u=3, i` | `request()`, `get()`, `post()`, ... |
|
|
123
|
+
| `generic` | `empty` | `u=3, i` | |
|
|
124
|
+
|
|
125
|
+
Setting `Client(context=...)` makes that context the default for every call
|
|
126
|
+
on that client.
|
|
127
|
+
|
|
128
|
+
When you pass `referer=`, `Sec-Fetch-Site` is worked out from the referer and
|
|
129
|
+
the request URL (`same-origin`, `same-site` or `cross-site`), as Chrome does.
|
|
130
|
+
Without one, a `document` request is sent as `none`, like a URL typed into the
|
|
131
|
+
address bar. `cache-control: max-age=0`, which Chrome sends only on reload, is
|
|
132
|
+
not sent.
|
|
133
|
+
|
|
134
|
+
## Snapshots: following Chrome, or pinning it
|
|
135
|
+
|
|
136
|
+
Chrome keeps changing its headers and TLS/HTTP-2 fingerprint, and this
|
|
137
|
+
library updates to match. Everything that goes on the wire (User-Agent,
|
|
138
|
+
client hints, header order, `Accept` values, priorities, TLS profile) comes
|
|
139
|
+
from a **snapshot**, named after the date it was captured and verified
|
|
140
|
+
against a real Chrome:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
its_a_me_chrome.get(url) # snapshot="latest"
|
|
144
|
+
its_a_me_chrome.get(url, snapshot="20261129") # pinned
|
|
145
|
+
its_a_me_chrome.Client(snapshot="20261129")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
* `"latest"` (the default) means you're OK with the requests changing when
|
|
149
|
+
you upgrade its-a-me-chrome.
|
|
150
|
+
* A dated snapshot sends exactly the same bytes in every later release.
|
|
151
|
+
Pinning a snapshot your installed version doesn't have raises
|
|
152
|
+
`ValueError`. Pins older than a year emit `SnapshotAgeWarning`, since
|
|
153
|
+
servers may start flagging an old Chrome.
|
|
154
|
+
|
|
155
|
+
The snapshot actually used is on every result as `result.profile.snapshot`
|
|
156
|
+
(`"latest"` is resolved to its date), so you can log it. Available snapshots
|
|
157
|
+
are in `its_a_me_chrome.SNAPSHOTS`; `get_snapshot(name)` returns one as a
|
|
158
|
+
`ChromeProfile`, which you can adjust and pass as `profile=`:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from dataclasses import replace
|
|
162
|
+
profile = replace(its_a_me_chrome.get_snapshot("20261129"),
|
|
163
|
+
accept_language="fr-FR,fr;q=0.9")
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
| snapshot | Chrome | TLS/HTTP-2 (`curl_cffi`) |
|
|
167
|
+
|------------|--------|--------------------------|
|
|
168
|
+
| `20261129` | 158 | `chrome152` |
|
|
169
|
+
|
|
170
|
+
## API
|
|
171
|
+
|
|
172
|
+
One-shot functions (each opens and closes its own session):
|
|
173
|
+
|
|
174
|
+
* `download(url, path, *, context, referer, headers, params, overwrite, raise_for_status, profile, snapshot, verify, timeout, proxy) -> DownloadResult`
|
|
175
|
+
* `fetch(url, *, context, referer, headers, params, raise_for_status, profile, snapshot, verify, timeout, proxy) -> bytes`
|
|
176
|
+
* `request(method, url, *, params, data, json, context, referer, headers, raise_for_status, allow_redirects, profile, snapshot, verify, timeout, proxy) -> Response`
|
|
177
|
+
* `get`, `post`, `put`, `patch`, `delete`, `head`, `options` — same options as `request`
|
|
178
|
+
|
|
179
|
+
`Client(profile=None, *, snapshot, context, referer, verify, timeout, proxy, headers)` has
|
|
180
|
+
the same methods; their options override the client's defaults.
|
|
181
|
+
|
|
182
|
+
Results (`Response` and `DownloadResult` have these in common):
|
|
183
|
+
|
|
184
|
+
* `.url` (final URL after redirects), `.requested_url`
|
|
185
|
+
* `.status_code`, `.reason`, `.ok`, `.raise_for_status()`
|
|
186
|
+
* `.headers` — case-insensitive; `.headers.get_list("set-cookie")` for repeated headers
|
|
187
|
+
* `.content_type`, `.http_version`, `.elapsed` (seconds), `.context`, `.profile`
|
|
188
|
+
|
|
189
|
+
`Response` adds `.method`, `.content` / `.body` (bytes), `.encoding`,
|
|
190
|
+
`.text`, `.json()`. `DownloadResult` adds `.path` and `.size`.
|
|
191
|
+
|
|
192
|
+
`ChromeProfile` describes the Chrome being impersonated (`version`,
|
|
193
|
+
`impersonate`, `platform`, `accept_language`, `accept_encoding`, header order,
|
|
194
|
+
contexts, priorities, and the `snapshot` it comes from). `ChromeProfile()` is
|
|
195
|
+
the latest snapshot. Pass either `profile=` or `snapshot=`, not both.
|
|
196
|
+
|
|
197
|
+
> `ChromeDownloader` is the former name of `Client` and still works.
|
|
198
|
+
|
|
199
|
+
## Examples
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
uv run python examples/download.py <URL> <OUTPUT> [--context image] [--referer ...]
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
uv run python examples/reuse_session.py URL [URL ...] --outdir /tmp
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
uv run python examples/request.py <URL> [--context document] [--method POST] [--json '{"q":1}']
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Against a self-signed host, add `--insecure`.
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
uv run python examples/localhost_page.py # loads https://localhost:8443/fingerprint as a page
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Development
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
uv run pytest
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The tests run against a local HTTP server and need no network access.
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# its-a-me-chrome
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/bertrandom/its-a-me-chrome/main/assets/chrome.jpg" alt="A cartoon Chrome logo in a red cap and overalls, holding a wrench, says "It's-a me, Chrome!" in a pixel-art desert with a T-rex and pterodactyls" width="830">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
Fetch URLs — download files, load pages, call APIs — with the network
|
|
8
|
+
fingerprint of a **real Chrome browser**.
|
|
9
|
+
|
|
10
|
+
`its-a-me-chrome` wraps [`curl_cffi`](https://github.com/lexiforest/curl_cffi)
|
|
11
|
+
(curl-impersonate) and reproduces:
|
|
12
|
+
|
|
13
|
+
* the **TLS ClientHello / JA3 / JA4** and **HTTP/2** fingerprint of Chrome
|
|
14
|
+
(`chrome152`, verified to match Chrome 158);
|
|
15
|
+
* the real Chrome `User-Agent`;
|
|
16
|
+
* Chrome's exact header set **and header order**;
|
|
17
|
+
* the `priority: u=N, i` header and the matching HTTP/2 `PRIORITY` weight.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv add its-a-me-chrome # from a git/path source
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import its_a_me_chrome
|
|
29
|
+
|
|
30
|
+
# Download a file (streamed to disk, written atomically)
|
|
31
|
+
result = its_a_me_chrome.download("https://example.com/cat.jpg", "cat.jpg")
|
|
32
|
+
print(result.path, result.size)
|
|
33
|
+
|
|
34
|
+
# Load a page as a top-level navigation would
|
|
35
|
+
page = its_a_me_chrome.get("https://example.com", context="document")
|
|
36
|
+
print(page.text[:200])
|
|
37
|
+
|
|
38
|
+
# Call a JSON API
|
|
39
|
+
data = its_a_me_chrome.post("https://api.example.com/search",
|
|
40
|
+
json={"q": "cats"},
|
|
41
|
+
headers={"x-api-key": token}).json()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Reusing a session
|
|
45
|
+
|
|
46
|
+
A `Client` keeps connections and cookies between requests, like one browser
|
|
47
|
+
tab. Defaults you pass to it apply to every call and can be overridden per
|
|
48
|
+
call.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
with its_a_me_chrome.Client(referer="https://example.com/") as client:
|
|
52
|
+
client.download(url1, "a.jpg")
|
|
53
|
+
client.download(url2, "downloads/") # filename from server or URL
|
|
54
|
+
body = client.fetch(url3) # bytes, nothing written
|
|
55
|
+
data = client.get(api_url, params={"page": 2}).json()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Errors
|
|
59
|
+
|
|
60
|
+
All errors derive from `its_a_me_chrome.ItsAMeChromeError`:
|
|
61
|
+
|
|
62
|
+
| exception | when |
|
|
63
|
+
|---------------|-------------------------------------------------------------|
|
|
64
|
+
| `RequestError`| DNS, TLS, connection failures |
|
|
65
|
+
| `Timeout` | the request took longer than `timeout` (a `RequestError`) |
|
|
66
|
+
| `HTTPError` | non-2xx status; `.status_code`, `.url`, and `.response` |
|
|
67
|
+
|
|
68
|
+
Non-2xx responses raise by default. Pass `raise_for_status=False` to get
|
|
69
|
+
the response back instead, then check `.ok`. For `request`/`get`/..., the
|
|
70
|
+
error carries the full response, so the error body is not lost:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
try:
|
|
74
|
+
its_a_me_chrome.get(url)
|
|
75
|
+
except its_a_me_chrome.HTTPError as err:
|
|
76
|
+
print(err.status_code, err.response.text)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`download()` raises `FileExistsError` **before sending anything** if the
|
|
80
|
+
target file exists, unless you pass `overwrite=True`.
|
|
81
|
+
|
|
82
|
+
## Request contexts
|
|
83
|
+
|
|
84
|
+
`context=` sets the `Sec-Fetch-*` / `Accept` headers and the priority to match
|
|
85
|
+
how Chrome tags each resource type:
|
|
86
|
+
|
|
87
|
+
| context | `Sec-Fetch-Dest` | `priority` | default for |
|
|
88
|
+
|------------|------------------|------------|-------------------------------------|
|
|
89
|
+
| `image` | `image` | `u=2, i` | `download()`, `fetch()` |
|
|
90
|
+
| `document` | `document` | `u=0, i` | — (use for HTML pages) |
|
|
91
|
+
| `script` | `script` | `u=2, i` | |
|
|
92
|
+
| `style` | `style` | `u=2, i` | |
|
|
93
|
+
| `font` | `font` | `u=3, i` | |
|
|
94
|
+
| `fetch` | `empty` | `u=3, i` | `request()`, `get()`, `post()`, ... |
|
|
95
|
+
| `generic` | `empty` | `u=3, i` | |
|
|
96
|
+
|
|
97
|
+
Setting `Client(context=...)` makes that context the default for every call
|
|
98
|
+
on that client.
|
|
99
|
+
|
|
100
|
+
When you pass `referer=`, `Sec-Fetch-Site` is worked out from the referer and
|
|
101
|
+
the request URL (`same-origin`, `same-site` or `cross-site`), as Chrome does.
|
|
102
|
+
Without one, a `document` request is sent as `none`, like a URL typed into the
|
|
103
|
+
address bar. `cache-control: max-age=0`, which Chrome sends only on reload, is
|
|
104
|
+
not sent.
|
|
105
|
+
|
|
106
|
+
## Snapshots: following Chrome, or pinning it
|
|
107
|
+
|
|
108
|
+
Chrome keeps changing its headers and TLS/HTTP-2 fingerprint, and this
|
|
109
|
+
library updates to match. Everything that goes on the wire (User-Agent,
|
|
110
|
+
client hints, header order, `Accept` values, priorities, TLS profile) comes
|
|
111
|
+
from a **snapshot**, named after the date it was captured and verified
|
|
112
|
+
against a real Chrome:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
its_a_me_chrome.get(url) # snapshot="latest"
|
|
116
|
+
its_a_me_chrome.get(url, snapshot="20261129") # pinned
|
|
117
|
+
its_a_me_chrome.Client(snapshot="20261129")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
* `"latest"` (the default) means you're OK with the requests changing when
|
|
121
|
+
you upgrade its-a-me-chrome.
|
|
122
|
+
* A dated snapshot sends exactly the same bytes in every later release.
|
|
123
|
+
Pinning a snapshot your installed version doesn't have raises
|
|
124
|
+
`ValueError`. Pins older than a year emit `SnapshotAgeWarning`, since
|
|
125
|
+
servers may start flagging an old Chrome.
|
|
126
|
+
|
|
127
|
+
The snapshot actually used is on every result as `result.profile.snapshot`
|
|
128
|
+
(`"latest"` is resolved to its date), so you can log it. Available snapshots
|
|
129
|
+
are in `its_a_me_chrome.SNAPSHOTS`; `get_snapshot(name)` returns one as a
|
|
130
|
+
`ChromeProfile`, which you can adjust and pass as `profile=`:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from dataclasses import replace
|
|
134
|
+
profile = replace(its_a_me_chrome.get_snapshot("20261129"),
|
|
135
|
+
accept_language="fr-FR,fr;q=0.9")
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| snapshot | Chrome | TLS/HTTP-2 (`curl_cffi`) |
|
|
139
|
+
|------------|--------|--------------------------|
|
|
140
|
+
| `20261129` | 158 | `chrome152` |
|
|
141
|
+
|
|
142
|
+
## API
|
|
143
|
+
|
|
144
|
+
One-shot functions (each opens and closes its own session):
|
|
145
|
+
|
|
146
|
+
* `download(url, path, *, context, referer, headers, params, overwrite, raise_for_status, profile, snapshot, verify, timeout, proxy) -> DownloadResult`
|
|
147
|
+
* `fetch(url, *, context, referer, headers, params, raise_for_status, profile, snapshot, verify, timeout, proxy) -> bytes`
|
|
148
|
+
* `request(method, url, *, params, data, json, context, referer, headers, raise_for_status, allow_redirects, profile, snapshot, verify, timeout, proxy) -> Response`
|
|
149
|
+
* `get`, `post`, `put`, `patch`, `delete`, `head`, `options` — same options as `request`
|
|
150
|
+
|
|
151
|
+
`Client(profile=None, *, snapshot, context, referer, verify, timeout, proxy, headers)` has
|
|
152
|
+
the same methods; their options override the client's defaults.
|
|
153
|
+
|
|
154
|
+
Results (`Response` and `DownloadResult` have these in common):
|
|
155
|
+
|
|
156
|
+
* `.url` (final URL after redirects), `.requested_url`
|
|
157
|
+
* `.status_code`, `.reason`, `.ok`, `.raise_for_status()`
|
|
158
|
+
* `.headers` — case-insensitive; `.headers.get_list("set-cookie")` for repeated headers
|
|
159
|
+
* `.content_type`, `.http_version`, `.elapsed` (seconds), `.context`, `.profile`
|
|
160
|
+
|
|
161
|
+
`Response` adds `.method`, `.content` / `.body` (bytes), `.encoding`,
|
|
162
|
+
`.text`, `.json()`. `DownloadResult` adds `.path` and `.size`.
|
|
163
|
+
|
|
164
|
+
`ChromeProfile` describes the Chrome being impersonated (`version`,
|
|
165
|
+
`impersonate`, `platform`, `accept_language`, `accept_encoding`, header order,
|
|
166
|
+
contexts, priorities, and the `snapshot` it comes from). `ChromeProfile()` is
|
|
167
|
+
the latest snapshot. Pass either `profile=` or `snapshot=`, not both.
|
|
168
|
+
|
|
169
|
+
> `ChromeDownloader` is the former name of `Client` and still works.
|
|
170
|
+
|
|
171
|
+
## Examples
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
uv run python examples/download.py <URL> <OUTPUT> [--context image] [--referer ...]
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
uv run python examples/reuse_session.py URL [URL ...] --outdir /tmp
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
uv run python examples/request.py <URL> [--context document] [--method POST] [--json '{"q":1}']
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Against a self-signed host, add `--insecure`.
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
uv run python examples/localhost_page.py # loads https://localhost:8443/fingerprint as a page
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Development
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
uv run pytest
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The tests run against a local HTTP server and need no network access.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "its-a-me-chrome"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Download files, retrieve pages and call APIs with a real-Chrome network fingerprint"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Bertrand Fan", email = "bert@bert.org" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"curl-cffi>=0.17.0",
|
|
14
|
+
]
|
|
15
|
+
keywords = ["chrome", "fingerprint", "tls", "ja3", "http2", "curl-cffi", "impersonate", "scraping"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
28
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/bertrandom/its-a-me-chrome"
|
|
33
|
+
Repository = "https://github.com/bertrandom/its-a-me-chrome"
|
|
34
|
+
Issues = "https://github.com/bertrandom/its-a-me-chrome/issues"
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["uv_build>=0.9.22,<0.10.0"]
|
|
38
|
+
build-backend = "uv_build"
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
dev = [
|
|
42
|
+
"pytest>=9.2.0",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
filterwarnings = ["ignore:Extra fingerprints were altered"]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""its-a-me-chrome -- fetch URLs with a real-Chrome network fingerprint.
|
|
2
|
+
|
|
3
|
+
Download a file::
|
|
4
|
+
|
|
5
|
+
import its_a_me_chrome
|
|
6
|
+
|
|
7
|
+
result = its_a_me_chrome.download("https://example.com/cat.jpg", "cat.jpg")
|
|
8
|
+
print(result.path, result.size)
|
|
9
|
+
|
|
10
|
+
Retrieve a page or call a JSON API::
|
|
11
|
+
|
|
12
|
+
page = its_a_me_chrome.get("https://example.com", context="document")
|
|
13
|
+
print(page.status_code, page.text[:15])
|
|
14
|
+
|
|
15
|
+
data = its_a_me_chrome.post("https://api.example.com/search",
|
|
16
|
+
json={"q": "cats"}).json()
|
|
17
|
+
|
|
18
|
+
Reuse one session across many requests::
|
|
19
|
+
|
|
20
|
+
with its_a_me_chrome.Client(referer="https://example.com/") as client:
|
|
21
|
+
client.download(url1, "a.jpg")
|
|
22
|
+
client.download(url2, "downloads/") # name from the server/URL
|
|
23
|
+
data = client.get(api_url).json()
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from importlib.metadata import PackageNotFoundError, version as _version
|
|
27
|
+
|
|
28
|
+
from .client import (
|
|
29
|
+
ChromeDownloader,
|
|
30
|
+
Client,
|
|
31
|
+
DownloadResult,
|
|
32
|
+
HTTPError,
|
|
33
|
+
RequestError,
|
|
34
|
+
Response,
|
|
35
|
+
ItsAMeChromeError,
|
|
36
|
+
Timeout,
|
|
37
|
+
delete,
|
|
38
|
+
download,
|
|
39
|
+
fetch,
|
|
40
|
+
get,
|
|
41
|
+
head,
|
|
42
|
+
options,
|
|
43
|
+
patch,
|
|
44
|
+
post,
|
|
45
|
+
put,
|
|
46
|
+
request,
|
|
47
|
+
)
|
|
48
|
+
from .profile import (
|
|
49
|
+
CONTEXTS,
|
|
50
|
+
DEFAULT_IMPERSONATE,
|
|
51
|
+
DEFAULT_VERSION,
|
|
52
|
+
LATEST_SNAPSHOT,
|
|
53
|
+
SNAPSHOTS,
|
|
54
|
+
URGENCY_WEIGHT,
|
|
55
|
+
ChromeProfile,
|
|
56
|
+
Context,
|
|
57
|
+
SnapshotAgeWarning,
|
|
58
|
+
get_snapshot,
|
|
59
|
+
build_extra_fingerprint,
|
|
60
|
+
build_headers,
|
|
61
|
+
header_order,
|
|
62
|
+
weight_for_priority,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
__version__ = _version("its-a-me-chrome")
|
|
67
|
+
except PackageNotFoundError: # running from a source checkout
|
|
68
|
+
__version__ = "0.0.0"
|
|
69
|
+
|
|
70
|
+
__all__ = [
|
|
71
|
+
# sessions and one-shot helpers
|
|
72
|
+
"Client",
|
|
73
|
+
"ChromeDownloader",
|
|
74
|
+
"download",
|
|
75
|
+
"fetch",
|
|
76
|
+
"request",
|
|
77
|
+
"get",
|
|
78
|
+
"post",
|
|
79
|
+
"put",
|
|
80
|
+
"patch",
|
|
81
|
+
"delete",
|
|
82
|
+
"head",
|
|
83
|
+
"options",
|
|
84
|
+
# results
|
|
85
|
+
"DownloadResult",
|
|
86
|
+
"Response",
|
|
87
|
+
# errors
|
|
88
|
+
"ItsAMeChromeError",
|
|
89
|
+
"RequestError",
|
|
90
|
+
"Timeout",
|
|
91
|
+
"HTTPError",
|
|
92
|
+
# fingerprint profile
|
|
93
|
+
"ChromeProfile",
|
|
94
|
+
"Context",
|
|
95
|
+
"CONTEXTS",
|
|
96
|
+
"DEFAULT_IMPERSONATE",
|
|
97
|
+
"DEFAULT_VERSION",
|
|
98
|
+
# snapshots
|
|
99
|
+
"LATEST_SNAPSHOT",
|
|
100
|
+
"SNAPSHOTS",
|
|
101
|
+
"SnapshotAgeWarning",
|
|
102
|
+
"get_snapshot",
|
|
103
|
+
# low-level header building
|
|
104
|
+
"URGENCY_WEIGHT",
|
|
105
|
+
"build_extra_fingerprint",
|
|
106
|
+
"build_headers",
|
|
107
|
+
"header_order",
|
|
108
|
+
"weight_for_priority",
|
|
109
|
+
"__version__",
|
|
110
|
+
]
|