falseok 0.2.0__tar.gz → 0.3.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.
- {falseok-0.2.0/src/falseok.egg-info → falseok-0.3.0}/PKG-INFO +97 -29
- {falseok-0.2.0 → falseok-0.3.0}/README.md +96 -28
- {falseok-0.2.0 → falseok-0.3.0}/pyproject.toml +1 -1
- falseok-0.3.0/src/falseok/__init__.py +8 -0
- falseok-0.3.0/src/falseok/batch.py +51 -0
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok/cli.py +53 -10
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok/data.py +19 -1
- falseok-0.3.0/src/falseok/page.py +1521 -0
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok/signatures.json +140 -18
- {falseok-0.2.0 → falseok-0.3.0/src/falseok.egg-info}/PKG-INFO +97 -29
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok.egg-info/SOURCES.txt +1 -0
- falseok-0.3.0/tests/test_falseok.py +1309 -0
- falseok-0.2.0/src/falseok/__init__.py +0 -7
- falseok-0.2.0/src/falseok/page.py +0 -768
- falseok-0.2.0/tests/test_falseok.py +0 -513
- {falseok-0.2.0 → falseok-0.3.0}/LICENSE +0 -0
- {falseok-0.2.0 → falseok-0.3.0}/setup.cfg +0 -0
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok/__main__.py +0 -0
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok.egg-info/dependency_links.txt +0 -0
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok.egg-info/entry_points.txt +0 -0
- {falseok-0.2.0 → falseok-0.3.0}/src/falseok.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: falseok
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Catch the 200 OK that isn't: spot block pages and silently broken scraped data.
|
|
5
5
|
Author: Benchmarked
|
|
6
6
|
License: MIT
|
|
@@ -37,61 +37,79 @@ falseok data today.json --vs yesterday.json
|
|
|
37
37
|
Pure Python, zero dependencies, works with whatever fetches your pages. It recognises blocks. It never tries to get
|
|
38
38
|
around them.
|
|
39
39
|
|
|
40
|
-
## Twelve tools, the same
|
|
40
|
+
## Twelve tools, the same fresh pages
|
|
41
41
|
|
|
42
42
|
<!-- bench:start -->
|
|
43
43
|
<p align="center">
|
|
44
44
|
<picture>
|
|
45
45
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/bench-dark.svg">
|
|
46
|
-
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/bench-light.svg" alt="Twelve tools on the same
|
|
46
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/bench-light.svg" alt="Twelve tools on the same 982 fresh pages: falseok gave a wrong verdict on 3.2% of them, the next best tool on 9.9%; falseok caught 97.4% of the anti-bot blocks and 73.1% of the unusable 200 OK pages, and flagged 0.5% of the real pages" width="880">
|
|
47
47
|
</picture>
|
|
48
48
|
</p>
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
982 pages drawn at random from 40,432 fresh pages on 30,066 sites in 38 languages; no rule of any falseok version was written or tuned on them. Labels come from three independent reviewers; a page counts when at least two of them gave it the same label. The 144 hardest pages of the sample were then re-checked by hand and on screenshots, and that label wins. Every tool judged the same bytes, with the status code and the response headers. 982 pages got a label: 656 real, 117 anti-bot blocks, 141 other refusals, 68 empty. 104 of the 326 unusable pages came back without an error status; the table calls them "200 OK". A wrong verdict is an unusable page let through or a real page flagged, out of all 982.
|
|
51
51
|
|
|
52
52
|
| tool | wrong verdicts | blocks caught | unusable "200 OK" caught | real pages flagged | other refusals caught | empty pages caught | ms per page |
|
|
53
53
|
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
54
|
-
| **falseok** | **2
|
|
54
|
+
| **falseok** | **3.2%** | **97.4%** | **73.1%** | 0.5% | **90.1%** | **83.8%** | 1.59 |
|
|
55
55
|
| *Built for the same job* | | | | | | | |
|
|
56
|
-
| a Rust scraper's anti-bot classifier |
|
|
57
|
-
| the blocked-page detector of a popular Python crawler |
|
|
58
|
-
| a new Python response classifier |
|
|
59
|
-
| the most used anti-bot detector, JavaScript |
|
|
60
|
-
| a Rust challenge detector |
|
|
56
|
+
| a Rust scraper's anti-bot classifier | 16.8% | 94.9% | 33.7% | 0.2% | 16.3% | 41.2% | 1.68 |
|
|
57
|
+
| the blocked-page detector of a popular Python crawler | 16.8% | 94.9% | 33.7% | 0.2% | 16.3% | 41.2% | 3.15 |
|
|
58
|
+
| a new Python response classifier | 23.5% | 65.0% | 20.2% | 0.3% | 2.1% | 26.5% | 49.5 |
|
|
59
|
+
| the most used anti-bot detector, JavaScript | 25.3% | 63.2% | 3.8% | **0.0%** | 0.7% | 4.4% | 2.21 |
|
|
60
|
+
| a Rust challenge detector | 39.6% | 64.1% | 14.4% | 25.9% | 17.0% | 11.8% | 0.17 |
|
|
61
61
|
| *Rules inside scraping frameworks* | | | | | | | |
|
|
62
|
-
| the ban rule of the most used proxy-rotation add-on |
|
|
63
|
-
| the blocked-request rule of a major crawling framework |
|
|
64
|
-
| the challenge checks of the most used Cloudflare library |
|
|
62
|
+
| the ban rule of the most used proxy-rotation add-on | 9.9% | 96.6% | 6.7% | **0.0%** | 78.0% | 8.8% | 0.12 |
|
|
63
|
+
| the blocked-request rule of a major crawling framework | 21.9% | 94.0% | 0.0% | **0.0%** | 0.7% | 0.0% | 22.7 |
|
|
64
|
+
| the challenge checks of the most used Cloudflare library | 33.2% | 0.0% | 0.0% | **0.0%** | 0.0% | 0.0% | 0.02 |
|
|
65
65
|
| *One-line checks* | | | | | | | |
|
|
66
|
-
| status-code check (4xx/5xx = bad) |
|
|
67
|
-
| page-size check (under 10 KB = bad) |
|
|
68
|
-
| keyword search (captcha, blocked, access denied...) | 63.
|
|
66
|
+
| status-code check (4xx/5xx = bad) | 10.6% | 95.7% | 0.0% | **0.0%** | 78.0% | 0.0% | <0.01 |
|
|
67
|
+
| page-size check (under 10 KB = bad) | 14.6% | 92.3% | 42.3% | 1.5% | 38.3% | 45.6% | <0.01 |
|
|
68
|
+
| keyword search (captcha, blocked, access denied...) | 63.6% | 83.8% | 51.0% | 77.3% | 51.1% | 55.9% | 2.89 |
|
|
69
69
|
|
|
70
|
-
falseok gave a wrong verdict on 2
|
|
70
|
+
falseok gave a wrong verdict on 3.2% of the labelled pages; the next best tool, the ban rule of the most used proxy-rotation add-on, on 9.9%: **3.1 times fewer** wrong verdicts. Bold is the best value in a column. The one-line checks are the fastest because they read almost nothing: a status code, a length.
|
|
71
71
|
|
|
72
72
|
Some of these tools were built for a narrower job (only Cloudflare challenges, only status codes, only anti-bot vendors); the [benchmark](https://github.com/benchmarked-hq/falseok/blob/main/docs/benchmark.md) quotes what each one claims to catch, with 95% confidence intervals.
|
|
73
73
|
|
|
74
|
-
"Other refusals" are pages not found, server errors, login-only pages and the like. Most of them carry an error status, which is why a plain status check does well there (
|
|
74
|
+
"Other refusals" are pages not found, server errors, login-only pages and the like. Most of them carry an error status, which is why a plain status check does well there (78.0%) and catches no empty page at all.
|
|
75
75
|
|
|
76
|
-
**Where falseok loses: real pages flagged.** It flagged
|
|
76
|
+
**Where falseok loses: real pages flagged.** It flagged 3 of 656 real pages (0.5%). Five tools flagged none, two more flagged a single page. The 3 were short real pages (33, 57 and 961 characters of visible text) called empty. None of them was called an anti-bot block. The tools with zero false alarms judge only the status code or a few known signatures, or decline to judge many pages, and they catch 0 to 7 of the 104 unusable pages that came back without an error status; falseok caught 76.
|
|
77
77
|
|
|
78
|
-
**What it missed:**
|
|
78
|
+
**What it missed:** 3 of the 117 blocks, all served with status `200`.
|
|
79
79
|
|
|
80
|
-
**Speed:** about 1.
|
|
80
|
+
**Speed:** about 1.4 times faster than the most used JavaScript detector, level with the Rust classifier, about 31.2 times faster than the new Python classifier. The quickest checks (the Rust challenge detector, the proxy add-on's ban rule, the Cloudflare checks, status code, page size) are faster still, because they read almost nothing or stop at the first match. Next to a download of 500 ms or more, under 2 ms is noise.
|
|
81
81
|
<!-- bench:end -->
|
|
82
82
|
|
|
83
|
+
The table above was measured with 0.3.0, code frozen, on pages no version was tuned on. How 0.3 compares with 0.1 and 0.2 on the same fresh pages and made-up addresses:
|
|
84
|
+
|
|
85
|
+
<p align="center">
|
|
86
|
+
<picture>
|
|
87
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/versions-dark.svg">
|
|
88
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/versions-light.svg" alt="Three versions on the same fresh pages (982 labelled pages and 5,315 made-up addresses): 0.3 checks a page in 1.68 ms (0.1: 15.4 ms, 0.2: 2.15 ms), catches 74.6% of made-up addresses that answer 200 OK (0.1: 64.2%), gets 96.8% of everyday pages right (0.1: 96.4%), and checks 2,000 files 3.6 times faster on all cores" width="880">
|
|
89
|
+
</picture>
|
|
90
|
+
</p>
|
|
91
|
+
|
|
92
|
+
## New in 0.3
|
|
93
|
+
|
|
94
|
+
<p align="center">
|
|
95
|
+
<picture>
|
|
96
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/new03-dark.svg">
|
|
97
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/new03-light.svg" alt="New in 0.3: where the request ended up (url, final_url), what to do next (action, confidence, retry_after), page facts, your own rules, many pages at once (check_pages, --jobs)" width="880">
|
|
98
|
+
</picture>
|
|
99
|
+
</p>
|
|
100
|
+
|
|
83
101
|
## More than a block detector
|
|
84
102
|
|
|
85
103
|
<!-- more:start -->
|
|
86
104
|
<p align="center">
|
|
87
105
|
<picture>
|
|
88
106
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/more-dark.svg">
|
|
89
|
-
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/more-light.svg" alt="More than a block detector: page not found
|
|
107
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/more-light.svg" alt="More than a block detector: page not found 92.4% of 5,315 made-up addresses, empty shells 83.8%, block markers in the response headers of 4 anti-bot services, 44 languages, 1,020 of 1,020 broken dataset days caught" width="880">
|
|
90
108
|
</picture>
|
|
91
109
|
</p>
|
|
92
110
|
|
|
93
|
-
- **Page not found:**
|
|
94
|
-
- **Empty shells:**
|
|
111
|
+
- **Page not found:** 4,910 of 5,315 made-up addresses on real sites (92.4%), including 173 of the 232 that answered `200 OK` at the same address; 5,158 (97.0%) when you also pass `url` and `final_url`.
|
|
112
|
+
- **Empty shells:** 57 of 68 pages that loaded a menu and a footer and nothing else.
|
|
95
113
|
- **Response headers:** pass them (`--headers`, or `headers=` in Python) and it reads the anti-bot service's own
|
|
96
114
|
block marker and names the vendor (4 services so far).
|
|
97
115
|
- **44 languages:** "page not found", "access denied" and the other wording sites write themselves, each phrase
|
|
@@ -102,8 +120,8 @@ Some of these tools were built for a narrower job (only Cloudflare challenges, o
|
|
|
102
120
|
|
|
103
121
|
Three things we learned the hard way:
|
|
104
122
|
|
|
105
|
-
- **Status codes lie.**
|
|
106
|
-
- **Grepping for "captcha" flags
|
|
123
|
+
- **Status codes lie.** 104 of the 326 unusable pages in the benchmark came back without an error status. A status check calls all of them a success.
|
|
124
|
+
- **Grepping for "captcha" flags 77% of real pages** (507 of 656). Anti-bot scripts, signup captchas and cookie
|
|
107
125
|
banners load on normal pages too.
|
|
108
126
|
- **Block pages are short. Real pages aren't.** The block pages we measured carry 0 to ~2,000 characters of visible
|
|
109
127
|
text. That one fact does most of the work, and it is also where falseok's few false alarms come from.
|
|
@@ -118,6 +136,16 @@ falseok page page.html --headers headers.txt # the response headers, as `curl
|
|
|
118
136
|
falseok page page.html --json
|
|
119
137
|
```
|
|
120
138
|
|
|
139
|
+
### Where the request ended up
|
|
140
|
+
|
|
141
|
+
Give the address you asked for and the one you landed on after redirects (`--final-url` may be relative). A deep
|
|
142
|
+
link that ended on a sign-in, consent, error or home page, on a captcha or challenge address, or on a search that
|
|
143
|
+
lost its words is flagged even when the page itself looks fine. Without them nothing changes.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
falseok page page.html --url https://example.com/item/123 --final-url "/login?next=/item/123" # login_wall
|
|
147
|
+
```
|
|
148
|
+
|
|
121
149
|
<p align="center">
|
|
122
150
|
<picture>
|
|
123
151
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/verdicts-dark.svg">
|
|
@@ -144,6 +172,42 @@ falseok page page.html --json
|
|
|
144
172
|
|
|
145
173
|
</details>
|
|
146
174
|
|
|
175
|
+
### What to do next
|
|
176
|
+
|
|
177
|
+
Every result also carries an `action`: `keep`, `render_js` (the content needs a browser to appear), `retry`,
|
|
178
|
+
`backoff` (wait, then retry slower; `retry_after` holds the seconds when the server sent `Retry-After`), `drop`,
|
|
179
|
+
`decompress` (the body is still packed) or `stop` (the site refuses this client or wants a person; falseok does not
|
|
180
|
+
suggest ways around a block). `confidence` is `high`, `medium` or `low`: a vendor, a response header or the status
|
|
181
|
+
is sure, a page's wording less so, a guess from the page's shape least. The table and the rules are in
|
|
182
|
+
[docs/verdicts.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/verdicts.md).
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
challenge [Cloudflare]: cf-mitigated-header (header: "cf-mitigated: challenge") -> stop (high confidence)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Adjust the rules
|
|
189
|
+
|
|
190
|
+
Add your own rules on top of the bundled ones (same JSON format; one with an existing id replaces it), turn rule or
|
|
191
|
+
signal ids off, or accept a category you expect, such as a login wall when you scrape behind a login:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
falseok page page.html --extra-signatures my_rules.json --disable enable-js --allow login_wall
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
r = check_page(html, signatures=load_signatures(extra_signatures="my_rules.json"), allow_categories=["login_wall"])
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Details in [docs/signatures.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/signatures.md#adjust-the-rules).
|
|
202
|
+
|
|
203
|
+
Many pages at once: `falseok page pages/*.html --jobs 0` uses every CPU core; the answers and their order are the
|
|
204
|
+
same as with one. In Python, `falseok.check_pages(items, jobs=None)` takes html (or dicts of `check_page` arguments)
|
|
205
|
+
and returns a list of results in the same order.
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
results = falseok.check_pages([{"html": body, "status": 200} for body in bodies], jobs=4)
|
|
209
|
+
```
|
|
210
|
+
|
|
147
211
|
## Check data
|
|
148
212
|
|
|
149
213
|
```bash
|
|
@@ -176,8 +240,11 @@ import falseok
|
|
|
176
240
|
|
|
177
241
|
r = falseok.check_page(html, status=200) # html can be text or the raw bytes you received
|
|
178
242
|
r = falseok.check_page(resp.content, status=resp.status_code, headers=resp.headers) # headers are optional
|
|
243
|
+
r = falseok.check_page(resp.content, url=asked_url, final_url=resp.url) # where the redirects ended, optional
|
|
179
244
|
if not r.ok:
|
|
180
245
|
print(r.verdict, r.reason) # captcha robot-check-title (title: "Robot Check")
|
|
246
|
+
print(r.action, r.confidence, r.retry_after) # keep / render_js / retry / backoff / drop / decompress / stop
|
|
247
|
+
print(r.content_kind, r.canonical_url, r.meta_refresh, r.script_count) # html / document / data / compressed / binary / empty
|
|
181
248
|
|
|
182
249
|
report = falseok.compare(rows_today, rows_yesterday)
|
|
183
250
|
for issue in report.issues:
|
|
@@ -188,10 +255,11 @@ for issue in report.issues:
|
|
|
188
255
|
|
|
189
256
|
- **A stress suite** written to break it: random bytes, 50 MB pages, unclosed tags, every rule's wording hidden in
|
|
190
257
|
long real pages, Excel CSVs, JSON nested three levels down, a million rows. The first run found 107 failures. All
|
|
191
|
-
fixed, all still in the suite, which now holds
|
|
258
|
+
fixed, all still in the suite, which now holds 2,462 tests.
|
|
192
259
|
- **140,000 random inputs** from property-based testing. Nothing broke.
|
|
193
|
-
- **
|
|
194
|
-
quote
|
|
260
|
+
- **Five fresh sets of pages** from sites it had never seen. Every set that showed misses we then fixed became a
|
|
261
|
+
working set, so we don't quote it as proof (the 0.2.0 benchmark set is one of them now). The benchmark above is the
|
|
262
|
+
untouched half of a random sample from the fifth set (40,432 pages), scored with the code frozen.
|
|
195
263
|
- **Linux, macOS and Windows, Python 3.10 to 3.14**, on every change.
|
|
196
264
|
|
|
197
265
|
The whole story, failures included: [docs/testing.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/testing.md).
|
|
@@ -19,61 +19,79 @@ falseok data today.json --vs yesterday.json
|
|
|
19
19
|
Pure Python, zero dependencies, works with whatever fetches your pages. It recognises blocks. It never tries to get
|
|
20
20
|
around them.
|
|
21
21
|
|
|
22
|
-
## Twelve tools, the same
|
|
22
|
+
## Twelve tools, the same fresh pages
|
|
23
23
|
|
|
24
24
|
<!-- bench:start -->
|
|
25
25
|
<p align="center">
|
|
26
26
|
<picture>
|
|
27
27
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/bench-dark.svg">
|
|
28
|
-
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/bench-light.svg" alt="Twelve tools on the same
|
|
28
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/bench-light.svg" alt="Twelve tools on the same 982 fresh pages: falseok gave a wrong verdict on 3.2% of them, the next best tool on 9.9%; falseok caught 97.4% of the anti-bot blocks and 73.1% of the unusable 200 OK pages, and flagged 0.5% of the real pages" width="880">
|
|
29
29
|
</picture>
|
|
30
30
|
</p>
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
982 pages drawn at random from 40,432 fresh pages on 30,066 sites in 38 languages; no rule of any falseok version was written or tuned on them. Labels come from three independent reviewers; a page counts when at least two of them gave it the same label. The 144 hardest pages of the sample were then re-checked by hand and on screenshots, and that label wins. Every tool judged the same bytes, with the status code and the response headers. 982 pages got a label: 656 real, 117 anti-bot blocks, 141 other refusals, 68 empty. 104 of the 326 unusable pages came back without an error status; the table calls them "200 OK". A wrong verdict is an unusable page let through or a real page flagged, out of all 982.
|
|
33
33
|
|
|
34
34
|
| tool | wrong verdicts | blocks caught | unusable "200 OK" caught | real pages flagged | other refusals caught | empty pages caught | ms per page |
|
|
35
35
|
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
36
|
-
| **falseok** | **2
|
|
36
|
+
| **falseok** | **3.2%** | **97.4%** | **73.1%** | 0.5% | **90.1%** | **83.8%** | 1.59 |
|
|
37
37
|
| *Built for the same job* | | | | | | | |
|
|
38
|
-
| a Rust scraper's anti-bot classifier |
|
|
39
|
-
| the blocked-page detector of a popular Python crawler |
|
|
40
|
-
| a new Python response classifier |
|
|
41
|
-
| the most used anti-bot detector, JavaScript |
|
|
42
|
-
| a Rust challenge detector |
|
|
38
|
+
| a Rust scraper's anti-bot classifier | 16.8% | 94.9% | 33.7% | 0.2% | 16.3% | 41.2% | 1.68 |
|
|
39
|
+
| the blocked-page detector of a popular Python crawler | 16.8% | 94.9% | 33.7% | 0.2% | 16.3% | 41.2% | 3.15 |
|
|
40
|
+
| a new Python response classifier | 23.5% | 65.0% | 20.2% | 0.3% | 2.1% | 26.5% | 49.5 |
|
|
41
|
+
| the most used anti-bot detector, JavaScript | 25.3% | 63.2% | 3.8% | **0.0%** | 0.7% | 4.4% | 2.21 |
|
|
42
|
+
| a Rust challenge detector | 39.6% | 64.1% | 14.4% | 25.9% | 17.0% | 11.8% | 0.17 |
|
|
43
43
|
| *Rules inside scraping frameworks* | | | | | | | |
|
|
44
|
-
| the ban rule of the most used proxy-rotation add-on |
|
|
45
|
-
| the blocked-request rule of a major crawling framework |
|
|
46
|
-
| the challenge checks of the most used Cloudflare library |
|
|
44
|
+
| the ban rule of the most used proxy-rotation add-on | 9.9% | 96.6% | 6.7% | **0.0%** | 78.0% | 8.8% | 0.12 |
|
|
45
|
+
| the blocked-request rule of a major crawling framework | 21.9% | 94.0% | 0.0% | **0.0%** | 0.7% | 0.0% | 22.7 |
|
|
46
|
+
| the challenge checks of the most used Cloudflare library | 33.2% | 0.0% | 0.0% | **0.0%** | 0.0% | 0.0% | 0.02 |
|
|
47
47
|
| *One-line checks* | | | | | | | |
|
|
48
|
-
| status-code check (4xx/5xx = bad) |
|
|
49
|
-
| page-size check (under 10 KB = bad) |
|
|
50
|
-
| keyword search (captcha, blocked, access denied...) | 63.
|
|
48
|
+
| status-code check (4xx/5xx = bad) | 10.6% | 95.7% | 0.0% | **0.0%** | 78.0% | 0.0% | <0.01 |
|
|
49
|
+
| page-size check (under 10 KB = bad) | 14.6% | 92.3% | 42.3% | 1.5% | 38.3% | 45.6% | <0.01 |
|
|
50
|
+
| keyword search (captcha, blocked, access denied...) | 63.6% | 83.8% | 51.0% | 77.3% | 51.1% | 55.9% | 2.89 |
|
|
51
51
|
|
|
52
|
-
falseok gave a wrong verdict on 2
|
|
52
|
+
falseok gave a wrong verdict on 3.2% of the labelled pages; the next best tool, the ban rule of the most used proxy-rotation add-on, on 9.9%: **3.1 times fewer** wrong verdicts. Bold is the best value in a column. The one-line checks are the fastest because they read almost nothing: a status code, a length.
|
|
53
53
|
|
|
54
54
|
Some of these tools were built for a narrower job (only Cloudflare challenges, only status codes, only anti-bot vendors); the [benchmark](https://github.com/benchmarked-hq/falseok/blob/main/docs/benchmark.md) quotes what each one claims to catch, with 95% confidence intervals.
|
|
55
55
|
|
|
56
|
-
"Other refusals" are pages not found, server errors, login-only pages and the like. Most of them carry an error status, which is why a plain status check does well there (
|
|
56
|
+
"Other refusals" are pages not found, server errors, login-only pages and the like. Most of them carry an error status, which is why a plain status check does well there (78.0%) and catches no empty page at all.
|
|
57
57
|
|
|
58
|
-
**Where falseok loses: real pages flagged.** It flagged
|
|
58
|
+
**Where falseok loses: real pages flagged.** It flagged 3 of 656 real pages (0.5%). Five tools flagged none, two more flagged a single page. The 3 were short real pages (33, 57 and 961 characters of visible text) called empty. None of them was called an anti-bot block. The tools with zero false alarms judge only the status code or a few known signatures, or decline to judge many pages, and they catch 0 to 7 of the 104 unusable pages that came back without an error status; falseok caught 76.
|
|
59
59
|
|
|
60
|
-
**What it missed:**
|
|
60
|
+
**What it missed:** 3 of the 117 blocks, all served with status `200`.
|
|
61
61
|
|
|
62
|
-
**Speed:** about 1.
|
|
62
|
+
**Speed:** about 1.4 times faster than the most used JavaScript detector, level with the Rust classifier, about 31.2 times faster than the new Python classifier. The quickest checks (the Rust challenge detector, the proxy add-on's ban rule, the Cloudflare checks, status code, page size) are faster still, because they read almost nothing or stop at the first match. Next to a download of 500 ms or more, under 2 ms is noise.
|
|
63
63
|
<!-- bench:end -->
|
|
64
64
|
|
|
65
|
+
The table above was measured with 0.3.0, code frozen, on pages no version was tuned on. How 0.3 compares with 0.1 and 0.2 on the same fresh pages and made-up addresses:
|
|
66
|
+
|
|
67
|
+
<p align="center">
|
|
68
|
+
<picture>
|
|
69
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/versions-dark.svg">
|
|
70
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/versions-light.svg" alt="Three versions on the same fresh pages (982 labelled pages and 5,315 made-up addresses): 0.3 checks a page in 1.68 ms (0.1: 15.4 ms, 0.2: 2.15 ms), catches 74.6% of made-up addresses that answer 200 OK (0.1: 64.2%), gets 96.8% of everyday pages right (0.1: 96.4%), and checks 2,000 files 3.6 times faster on all cores" width="880">
|
|
71
|
+
</picture>
|
|
72
|
+
</p>
|
|
73
|
+
|
|
74
|
+
## New in 0.3
|
|
75
|
+
|
|
76
|
+
<p align="center">
|
|
77
|
+
<picture>
|
|
78
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/new03-dark.svg">
|
|
79
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/new03-light.svg" alt="New in 0.3: where the request ended up (url, final_url), what to do next (action, confidence, retry_after), page facts, your own rules, many pages at once (check_pages, --jobs)" width="880">
|
|
80
|
+
</picture>
|
|
81
|
+
</p>
|
|
82
|
+
|
|
65
83
|
## More than a block detector
|
|
66
84
|
|
|
67
85
|
<!-- more:start -->
|
|
68
86
|
<p align="center">
|
|
69
87
|
<picture>
|
|
70
88
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/more-dark.svg">
|
|
71
|
-
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/more-light.svg" alt="More than a block detector: page not found
|
|
89
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/more-light.svg" alt="More than a block detector: page not found 92.4% of 5,315 made-up addresses, empty shells 83.8%, block markers in the response headers of 4 anti-bot services, 44 languages, 1,020 of 1,020 broken dataset days caught" width="880">
|
|
72
90
|
</picture>
|
|
73
91
|
</p>
|
|
74
92
|
|
|
75
|
-
- **Page not found:**
|
|
76
|
-
- **Empty shells:**
|
|
93
|
+
- **Page not found:** 4,910 of 5,315 made-up addresses on real sites (92.4%), including 173 of the 232 that answered `200 OK` at the same address; 5,158 (97.0%) when you also pass `url` and `final_url`.
|
|
94
|
+
- **Empty shells:** 57 of 68 pages that loaded a menu and a footer and nothing else.
|
|
77
95
|
- **Response headers:** pass them (`--headers`, or `headers=` in Python) and it reads the anti-bot service's own
|
|
78
96
|
block marker and names the vendor (4 services so far).
|
|
79
97
|
- **44 languages:** "page not found", "access denied" and the other wording sites write themselves, each phrase
|
|
@@ -84,8 +102,8 @@ Some of these tools were built for a narrower job (only Cloudflare challenges, o
|
|
|
84
102
|
|
|
85
103
|
Three things we learned the hard way:
|
|
86
104
|
|
|
87
|
-
- **Status codes lie.**
|
|
88
|
-
- **Grepping for "captcha" flags
|
|
105
|
+
- **Status codes lie.** 104 of the 326 unusable pages in the benchmark came back without an error status. A status check calls all of them a success.
|
|
106
|
+
- **Grepping for "captcha" flags 77% of real pages** (507 of 656). Anti-bot scripts, signup captchas and cookie
|
|
89
107
|
banners load on normal pages too.
|
|
90
108
|
- **Block pages are short. Real pages aren't.** The block pages we measured carry 0 to ~2,000 characters of visible
|
|
91
109
|
text. That one fact does most of the work, and it is also where falseok's few false alarms come from.
|
|
@@ -100,6 +118,16 @@ falseok page page.html --headers headers.txt # the response headers, as `curl
|
|
|
100
118
|
falseok page page.html --json
|
|
101
119
|
```
|
|
102
120
|
|
|
121
|
+
### Where the request ended up
|
|
122
|
+
|
|
123
|
+
Give the address you asked for and the one you landed on after redirects (`--final-url` may be relative). A deep
|
|
124
|
+
link that ended on a sign-in, consent, error or home page, on a captcha or challenge address, or on a search that
|
|
125
|
+
lost its words is flagged even when the page itself looks fine. Without them nothing changes.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
falseok page page.html --url https://example.com/item/123 --final-url "/login?next=/item/123" # login_wall
|
|
129
|
+
```
|
|
130
|
+
|
|
103
131
|
<p align="center">
|
|
104
132
|
<picture>
|
|
105
133
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/verdicts-dark.svg">
|
|
@@ -126,6 +154,42 @@ falseok page page.html --json
|
|
|
126
154
|
|
|
127
155
|
</details>
|
|
128
156
|
|
|
157
|
+
### What to do next
|
|
158
|
+
|
|
159
|
+
Every result also carries an `action`: `keep`, `render_js` (the content needs a browser to appear), `retry`,
|
|
160
|
+
`backoff` (wait, then retry slower; `retry_after` holds the seconds when the server sent `Retry-After`), `drop`,
|
|
161
|
+
`decompress` (the body is still packed) or `stop` (the site refuses this client or wants a person; falseok does not
|
|
162
|
+
suggest ways around a block). `confidence` is `high`, `medium` or `low`: a vendor, a response header or the status
|
|
163
|
+
is sure, a page's wording less so, a guess from the page's shape least. The table and the rules are in
|
|
164
|
+
[docs/verdicts.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/verdicts.md).
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
challenge [Cloudflare]: cf-mitigated-header (header: "cf-mitigated: challenge") -> stop (high confidence)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Adjust the rules
|
|
171
|
+
|
|
172
|
+
Add your own rules on top of the bundled ones (same JSON format; one with an existing id replaces it), turn rule or
|
|
173
|
+
signal ids off, or accept a category you expect, such as a login wall when you scrape behind a login:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
falseok page page.html --extra-signatures my_rules.json --disable enable-js --allow login_wall
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
r = check_page(html, signatures=load_signatures(extra_signatures="my_rules.json"), allow_categories=["login_wall"])
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Details in [docs/signatures.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/signatures.md#adjust-the-rules).
|
|
184
|
+
|
|
185
|
+
Many pages at once: `falseok page pages/*.html --jobs 0` uses every CPU core; the answers and their order are the
|
|
186
|
+
same as with one. In Python, `falseok.check_pages(items, jobs=None)` takes html (or dicts of `check_page` arguments)
|
|
187
|
+
and returns a list of results in the same order.
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
results = falseok.check_pages([{"html": body, "status": 200} for body in bodies], jobs=4)
|
|
191
|
+
```
|
|
192
|
+
|
|
129
193
|
## Check data
|
|
130
194
|
|
|
131
195
|
```bash
|
|
@@ -158,8 +222,11 @@ import falseok
|
|
|
158
222
|
|
|
159
223
|
r = falseok.check_page(html, status=200) # html can be text or the raw bytes you received
|
|
160
224
|
r = falseok.check_page(resp.content, status=resp.status_code, headers=resp.headers) # headers are optional
|
|
225
|
+
r = falseok.check_page(resp.content, url=asked_url, final_url=resp.url) # where the redirects ended, optional
|
|
161
226
|
if not r.ok:
|
|
162
227
|
print(r.verdict, r.reason) # captcha robot-check-title (title: "Robot Check")
|
|
228
|
+
print(r.action, r.confidence, r.retry_after) # keep / render_js / retry / backoff / drop / decompress / stop
|
|
229
|
+
print(r.content_kind, r.canonical_url, r.meta_refresh, r.script_count) # html / document / data / compressed / binary / empty
|
|
163
230
|
|
|
164
231
|
report = falseok.compare(rows_today, rows_yesterday)
|
|
165
232
|
for issue in report.issues:
|
|
@@ -170,10 +237,11 @@ for issue in report.issues:
|
|
|
170
237
|
|
|
171
238
|
- **A stress suite** written to break it: random bytes, 50 MB pages, unclosed tags, every rule's wording hidden in
|
|
172
239
|
long real pages, Excel CSVs, JSON nested three levels down, a million rows. The first run found 107 failures. All
|
|
173
|
-
fixed, all still in the suite, which now holds
|
|
240
|
+
fixed, all still in the suite, which now holds 2,462 tests.
|
|
174
241
|
- **140,000 random inputs** from property-based testing. Nothing broke.
|
|
175
|
-
- **
|
|
176
|
-
quote
|
|
242
|
+
- **Five fresh sets of pages** from sites it had never seen. Every set that showed misses we then fixed became a
|
|
243
|
+
working set, so we don't quote it as proof (the 0.2.0 benchmark set is one of them now). The benchmark above is the
|
|
244
|
+
untouched half of a random sample from the fifth set (40,432 pages), scored with the code frozen.
|
|
177
245
|
- **Linux, macOS and Windows, Python 3.10 to 3.14**, on every change.
|
|
178
246
|
|
|
179
247
|
The whole story, failures included: [docs/testing.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/testing.md).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""falseok: catch the 200 OK that isn't."""
|
|
2
|
+
__version__ = "0.3.0"
|
|
3
|
+
|
|
4
|
+
from .batch import check_pages # noqa: E402
|
|
5
|
+
from .data import DataReport, check_rows, compare, load_rows # noqa: E402
|
|
6
|
+
from .page import VERDICTS, PageResult, check_page, decode_html, load_signatures # noqa: E402
|
|
7
|
+
|
|
8
|
+
__all__ = ["check_page", "check_pages", "decode_html", "VERDICTS", "load_signatures", "PageResult", "compare", "check_rows", "load_rows", "DataReport"]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Check many pages at once, on every CPU core."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from concurrent.futures import ProcessPoolExecutor
|
|
6
|
+
from typing import List
|
|
7
|
+
|
|
8
|
+
from .page import PageResult, check_page
|
|
9
|
+
|
|
10
|
+
_COMMON: dict = {}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _start(common: dict) -> None:
|
|
14
|
+
"""Worker start-up: keep the shared keyword arguments (signatures included) once, not once per page."""
|
|
15
|
+
_COMMON.clear()
|
|
16
|
+
_COMMON.update(common)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _one(item, common: dict) -> PageResult:
|
|
20
|
+
"""Check one item (html, or a dict of check_page arguments that win over the shared ones)."""
|
|
21
|
+
if isinstance(item, dict):
|
|
22
|
+
return check_page(**{**common, **item})
|
|
23
|
+
return check_page(item, **common)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _work(item) -> PageResult:
|
|
27
|
+
"""What a worker process runs for one item; the result is pickled back with its lazy fields already resolved."""
|
|
28
|
+
return _one(item, _COMMON)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def check_pages(items, jobs=None, **common) -> List[PageResult]:
|
|
32
|
+
"""Check many pages and return a list of PageResult in the order of `items` (not a generator).
|
|
33
|
+
|
|
34
|
+
items: an iterable of html (str or bytes) or of dicts with check_page's keyword arguments (html, status,
|
|
35
|
+
headers, url, final_url, ...); a dict's values win over `common`.
|
|
36
|
+
jobs: worker processes; None means os.cpu_count(); 1 runs a plain loop in this process, no pool.
|
|
37
|
+
common: check_page keyword arguments applied to every page (signatures=, min_text=, status=, ...).
|
|
38
|
+
Each result equals what check_page gives for that page. A result's lazy text length and script count are
|
|
39
|
+
resolved in the worker before it travels back (PageResult.__getstate__ does this when it is pickled).
|
|
40
|
+
"""
|
|
41
|
+
items = list(items)
|
|
42
|
+
if jobs is None:
|
|
43
|
+
jobs = os.cpu_count() or 1
|
|
44
|
+
if not isinstance(jobs, int) or jobs < 1:
|
|
45
|
+
raise ValueError(f"jobs must be a whole number of 1 or more, got {jobs!r}")
|
|
46
|
+
jobs = min(jobs, len(items))
|
|
47
|
+
if jobs <= 1:
|
|
48
|
+
return [_one(i, common) for i in items]
|
|
49
|
+
chunk = max(1, min(64, len(items) // (jobs * 4)))
|
|
50
|
+
with ProcessPoolExecutor(max_workers=jobs, initializer=_start, initargs=(common,)) as pool:
|
|
51
|
+
return list(pool.map(_work, items, chunksize=chunk))
|
|
@@ -8,12 +8,17 @@ import os
|
|
|
8
8
|
import sys
|
|
9
9
|
|
|
10
10
|
from . import __version__
|
|
11
|
+
from .batch import check_pages
|
|
11
12
|
from .data import compare, load_rows
|
|
12
|
-
from .page import check_page, decode_html, load_signatures
|
|
13
|
+
from .page import _allowed, check_page, decode_html, load_signatures
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def _page(args) -> int:
|
|
16
|
-
|
|
17
|
+
off = {i.strip() for v in args.disable or () for i in v.split(",") if i.strip()} or None
|
|
18
|
+
allow = {c.strip() for v in args.allow or () for c in v.split(",") if c.strip()} or None
|
|
19
|
+
if allow:
|
|
20
|
+
_allowed(allow) # a bad name stops here, before any file is read
|
|
21
|
+
sigs = load_signatures(args.signatures, extra_signatures=args.extra_signatures, disable_ids=off)
|
|
17
22
|
status = args.status
|
|
18
23
|
if status is not None and not 100 <= status <= 599:
|
|
19
24
|
raise ValueError(f"--status must be between 100 and 599, got {status}")
|
|
@@ -30,6 +35,27 @@ def _page(args) -> int:
|
|
|
30
35
|
raise ValueError(f"{args.headers}: expected a JSON object of header names and values")
|
|
31
36
|
worst, out, stdin = 0, [], None
|
|
32
37
|
many = len(args.files) > 1
|
|
38
|
+
jobs = args.jobs
|
|
39
|
+
if jobs < 0:
|
|
40
|
+
raise ValueError(f"--jobs must be 0 (all cores) or more, got {jobs}")
|
|
41
|
+
jobs = (os.cpu_count() or 1) if jobs == 0 else jobs
|
|
42
|
+
kw = dict(status=status, signatures=sigs, headers=headers, # bytes: the headers may name the charset
|
|
43
|
+
url=args.url, final_url=args.final_url, disable_ids=off, allow_categories=allow)
|
|
44
|
+
|
|
45
|
+
def report(path, r):
|
|
46
|
+
"""Count one result toward the exit code and print it (or keep it for --json)."""
|
|
47
|
+
nonlocal worst
|
|
48
|
+
if not r.ok:
|
|
49
|
+
worst = max(worst, 1)
|
|
50
|
+
if args.json:
|
|
51
|
+
out.append({"file": path, **r.to_dict()})
|
|
52
|
+
else:
|
|
53
|
+
who = f" [{r.vendor}]" if r.vendor else ""
|
|
54
|
+
wait = f", retry after {r.retry_after:g} s" if r.retry_after is not None else ""
|
|
55
|
+
print(f"{path + ': ' if many else ''}{r.verdict}{who}: {r.reason} -> {r.action} "
|
|
56
|
+
f"({r.confidence} confidence{wait})", flush=True)
|
|
57
|
+
|
|
58
|
+
pending = [] # with --jobs: (path, data, error entry) read first, checked together, reported in the same order
|
|
33
59
|
for path in args.files:
|
|
34
60
|
try:
|
|
35
61
|
if path == "-":
|
|
@@ -43,16 +69,23 @@ def _page(args) -> int:
|
|
|
43
69
|
print(f"falseok: {path}: {e.strerror or e}", file=sys.stderr)
|
|
44
70
|
worst = 2
|
|
45
71
|
if args.json:
|
|
46
|
-
|
|
72
|
+
entry = {"file": path, "verdict": None, "error": e.strerror or str(e)}
|
|
73
|
+
if jobs == 1:
|
|
74
|
+
out.append(entry)
|
|
75
|
+
else:
|
|
76
|
+
pending.append((path, None, entry)) # keeps its place among the results
|
|
47
77
|
continue
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
worst = max(worst, 1)
|
|
51
|
-
if args.json:
|
|
52
|
-
out.append({"file": path, **r.to_dict()})
|
|
78
|
+
if jobs == 1:
|
|
79
|
+
report(path, check_page(data, **kw))
|
|
53
80
|
else:
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
pending.append((path, data, None))
|
|
82
|
+
if pending:
|
|
83
|
+
results = iter(check_pages([d for _, d, e in pending if e is None], jobs=jobs, **kw))
|
|
84
|
+
for path, _, entry in pending:
|
|
85
|
+
if entry is None:
|
|
86
|
+
report(path, next(results))
|
|
87
|
+
else:
|
|
88
|
+
out.append(entry)
|
|
56
89
|
if args.json:
|
|
57
90
|
print(json.dumps(out if many else out[0], indent=2, ensure_ascii=False))
|
|
58
91
|
return worst
|
|
@@ -84,7 +117,17 @@ def main(argv=None) -> int:
|
|
|
84
117
|
pg.add_argument("--status", type=int, help="the HTTP status you got")
|
|
85
118
|
pg.add_argument("--headers", metavar="FILE", help="the response headers you got: a file of 'Name: value' lines "
|
|
86
119
|
"(what `curl -D FILE` saves) or a JSON object")
|
|
120
|
+
pg.add_argument("--url", help="the address you asked for (applies to every file given)")
|
|
121
|
+
pg.add_argument("--final-url", metavar="URL", help="the address you ended up at after redirects; may be relative "
|
|
122
|
+
"to --url (applies to every file given)")
|
|
87
123
|
pg.add_argument("--signatures", help="use your own signatures JSON file")
|
|
124
|
+
pg.add_argument("--extra-signatures", metavar="FILE", help="more rules on top of the signatures, same JSON format; "
|
|
125
|
+
"a rule with the id of an existing one replaces it")
|
|
126
|
+
pg.add_argument("--disable", metavar="ID[,ID...]", action="append", help="ignore these signal ids (repeatable)")
|
|
127
|
+
pg.add_argument("--allow", metavar="CATEGORY[,CATEGORY...]", action="append",
|
|
128
|
+
help="accept these categories, e.g. login_wall when you scrape behind a login (repeatable)")
|
|
129
|
+
pg.add_argument("--jobs", type=int, default=1, metavar="N",
|
|
130
|
+
help="check this many files at once (default 1; 0 = every CPU core); the results are the same")
|
|
88
131
|
pg.add_argument("--json", action="store_true")
|
|
89
132
|
pg.set_defaults(fn=_page)
|
|
90
133
|
|