falseok 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.
- falseok-0.2.0/LICENSE +21 -0
- falseok-0.2.0/PKG-INFO +218 -0
- falseok-0.2.0/README.md +200 -0
- falseok-0.2.0/pyproject.toml +30 -0
- falseok-0.2.0/setup.cfg +4 -0
- falseok-0.2.0/src/falseok/__init__.py +7 -0
- falseok-0.2.0/src/falseok/__main__.py +5 -0
- falseok-0.2.0/src/falseok/cli.py +120 -0
- falseok-0.2.0/src/falseok/data.py +390 -0
- falseok-0.2.0/src/falseok/page.py +768 -0
- falseok-0.2.0/src/falseok/signatures.json +524 -0
- falseok-0.2.0/src/falseok.egg-info/PKG-INFO +218 -0
- falseok-0.2.0/src/falseok.egg-info/SOURCES.txt +15 -0
- falseok-0.2.0/src/falseok.egg-info/dependency_links.txt +1 -0
- falseok-0.2.0/src/falseok.egg-info/entry_points.txt +2 -0
- falseok-0.2.0/src/falseok.egg-info/top_level.txt +1 -0
- falseok-0.2.0/tests/test_falseok.py +513 -0
falseok-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Benchmarked
|
|
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.
|
falseok-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: falseok
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Catch the 200 OK that isn't: spot block pages and silently broken scraped data.
|
|
5
|
+
Author: Benchmarked
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://benchmarked.website
|
|
8
|
+
Keywords: scraping,web-scraping,captcha,data-quality,monitoring,soft-404
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
13
|
+
Classifier: Topic :: Software Development :: Testing
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<picture>
|
|
21
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/hero-dark.svg">
|
|
22
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/hero-light.svg" alt="falseok: catch the 200 OK that isn't" width="880">
|
|
23
|
+
</picture>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
**Your scraper didn't fail. It succeeded at saving a captcha.**
|
|
27
|
+
|
|
28
|
+
`falseok` tells you when a scraped page that came back `200 OK` is really a block, a login wall or an empty shell,
|
|
29
|
+
and when today's dataset quietly broke.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install falseok
|
|
33
|
+
falseok page product.html --status 200
|
|
34
|
+
falseok data today.json --vs yesterday.json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Pure Python, zero dependencies, works with whatever fetches your pages. It recognises blocks. It never tries to get
|
|
38
|
+
around them.
|
|
39
|
+
|
|
40
|
+
## Twelve tools, the same saved pages
|
|
41
|
+
|
|
42
|
+
<!-- bench:start -->
|
|
43
|
+
<p align="center">
|
|
44
|
+
<picture>
|
|
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 5,071 saved pages: falseok gave a wrong verdict on 2.5% of them, the next best tool on 8.2%; falseok caught 98.5% of the anti-bot blocks and 76.6% of the unusable 200 OK pages, and flagged 0.7% of the real pages" width="880">
|
|
47
|
+
</picture>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
5,071 pages from sites sampled automatically in 38 languages, fetched once, code frozen before any page was read or any tool was run. Every tool judged the same bytes, with the status code and the response headers. 5,067 pages got a label: 3,494 real, 588 anti-bot blocks, 646 other refusals, 339 empty. 444 of the 1,573 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 5,067.
|
|
51
|
+
|
|
52
|
+
| tool | wrong verdicts | blocks caught | unusable "200 OK" caught | real pages flagged | other refusals caught | empty pages caught | ms per page |
|
|
53
|
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
54
|
+
| **falseok** | **2.5%** | **98.5%** | **76.6%** | 0.7% | **95.0%** | **81.4%** | 1.91 |
|
|
55
|
+
| *Built for the same job* | | | | | | | |
|
|
56
|
+
| a Rust scraper's anti-bot classifier | 15.2% | 91.5% | 45.0% | 0.1% | 14.4% | 52.2% | 1.72 |
|
|
57
|
+
| the blocked-page detector of a popular Python crawler | 15.3% | 91.7% | 45.3% | 0.2% | 14.1% | 52.2% | 3.19 |
|
|
58
|
+
| a new Python response classifier | 22.2% | 61.9% | 21.6% | 0.3% | 1.1% | 25.7% | 57.3 |
|
|
59
|
+
| the most used anti-bot detector, JavaScript | 23.0% | 65.6% | 5.6% | **0.0%** | 0.5% | 5.9% | 2.54 |
|
|
60
|
+
| a Rust challenge detector | 34.3% | 58.5% | 12.4% | 18.3% | 13.8% | 13.0% | 0.21 |
|
|
61
|
+
| *Rules inside scraping frameworks* | | | | | | | |
|
|
62
|
+
| the ban rule of the most used proxy-rotation add-on | 8.2% | 94.0% | 6.1% | **0.0%** | 89.6% | 7.1% | 0.14 |
|
|
63
|
+
| the blocked-request rule of a major crawling framework | 20.2% | 90.1% | 0.2% | **0.0%** | 3.3% | 0.0% | 25.5 |
|
|
64
|
+
| the challenge checks of the most used Cloudflare library | 31.0% | 0.0% | 0.0% | **0.0%** | 0.0% | 0.0% | 0.02 |
|
|
65
|
+
| *One-line checks* | | | | | | | |
|
|
66
|
+
| status-code check (4xx/5xx = bad) | 8.8% | 93.5% | 0.0% | **0.0%** | 89.6% | 0.0% | <0.01 |
|
|
67
|
+
| page-size check (under 10 KB = bad) | 13.3% | 89.1% | 56.1% | 1.1% | 34.5% | 57.2% | <0.01 |
|
|
68
|
+
| keyword search (captcha, blocked, access denied...) | 63.0% | 84.4% | 49.1% | 76.1% | 58.2% | 50.1% | 3.06 |
|
|
69
|
+
|
|
70
|
+
falseok gave a wrong verdict on 2.5% of the labelled pages; the next best tool, the ban rule of the most used proxy-rotation add-on, on 8.2%: **3.3 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
|
+
|
|
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
|
+
|
|
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 (89.6%) and catches no empty page at all.
|
|
75
|
+
|
|
76
|
+
**Where falseok loses: real pages flagged.** It flagged 24 of 3,494 real pages (0.7%). Three tools flagged none, two more flagged a single page. Of the 24: 14 were called empty (real pages with very little text, among them a few search pages with no results), 3 were pages that are a login form, 6 were called a captcha or a challenge, and 1 was a real page its server sent with status `503`. 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 25 of the 444 unusable pages that came back without an error status; falseok caught 340.
|
|
77
|
+
|
|
78
|
+
**What it missed:** 9 of the 588 blocks, all served with status `200`.
|
|
79
|
+
|
|
80
|
+
**Speed:** about 1.3 times faster than the most used JavaScript detector, level with the Rust classifier, about 30.0 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
|
+
<!-- bench:end -->
|
|
82
|
+
|
|
83
|
+
## More than a block detector
|
|
84
|
+
|
|
85
|
+
<!-- more:start -->
|
|
86
|
+
<p align="center">
|
|
87
|
+
<picture>
|
|
88
|
+
<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 100% with the status, empty shells 81.4%, 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
|
+
</picture>
|
|
91
|
+
</p>
|
|
92
|
+
|
|
93
|
+
- **Page not found:** 529 of 529 pages that came back `404` or `410` with the status given, and 408 of 529 from the page alone, when your scraper didn't keep the status.
|
|
94
|
+
- **Empty shells:** 276 of 339 pages that loaded a menu and a footer and nothing else.
|
|
95
|
+
- **Response headers:** pass them (`--headers`, or `headers=` in Python) and it reads the anti-bot service's own
|
|
96
|
+
block marker and names the vendor (4 services so far).
|
|
97
|
+
- **44 languages:** "page not found", "access denied" and the other wording sites write themselves, each phrase
|
|
98
|
+
taken from a page that really came back.
|
|
99
|
+
- **Datasets:** on four real scraped datasets, it caught **1,020 of 1,020** deliberately broken days (lost rows,
|
|
100
|
+
emptied or vanished fields, frozen values, type changes, duplicates, block pages saved as rows) and stayed quiet on
|
|
101
|
+
**200 of 200** healthy ones. A row-count alert, what most pipelines have, caught 240.
|
|
102
|
+
|
|
103
|
+
Three things we learned the hard way:
|
|
104
|
+
|
|
105
|
+
- **Status codes lie.** 444 of the 1573 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 76% of real pages** (2660 of 3494). Anti-bot scripts, signup captchas and cookie
|
|
107
|
+
banners load on normal pages too.
|
|
108
|
+
- **Block pages are short. Real pages aren't.** The block pages we measured carry 0 to ~2,000 characters of visible
|
|
109
|
+
text. That one fact does most of the work, and it is also where falseok's few false alarms come from.
|
|
110
|
+
<!-- more:end -->
|
|
111
|
+
|
|
112
|
+
## Check pages
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
falseok page product.html
|
|
116
|
+
falseok page pages/*.html --status 200
|
|
117
|
+
falseok page page.html --headers headers.txt # the response headers, as `curl -D headers.txt` saves them
|
|
118
|
+
falseok page page.html --json
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
<p align="center">
|
|
122
|
+
<picture>
|
|
123
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/verdicts-dark.svg">
|
|
124
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/verdicts-light.svg" alt="Every page gets one verdict: ok, not_html, challenge, captcha, rate_limited, login_wall, consent_wall, soft_block, soft_404, empty_shell, http_error" width="880">
|
|
125
|
+
</picture>
|
|
126
|
+
</p>
|
|
127
|
+
|
|
128
|
+
<details>
|
|
129
|
+
<summary>The verdicts as text</summary>
|
|
130
|
+
|
|
131
|
+
| verdict | what it means |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `ok` | no block signal found |
|
|
134
|
+
| `not_html` | binary or compressed data, not a page |
|
|
135
|
+
| `challenge` | an anti-bot check page (the vendor is named when the HTML shows it) |
|
|
136
|
+
| `captcha` | a captcha in place of the content |
|
|
137
|
+
| `rate_limited` | "too many requests", or HTTP 429 |
|
|
138
|
+
| `login_wall` | you need to sign in to see this |
|
|
139
|
+
| `consent_wall` | a consent page in place of the content |
|
|
140
|
+
| `soft_block` | "access denied", "continue shopping", "something went wrong" served as 200 |
|
|
141
|
+
| `soft_404` | 200, but the page says it does not exist |
|
|
142
|
+
| `empty_shell` | empty response, a saved redirect, or a JavaScript app that never rendered |
|
|
143
|
+
| `http_error` | you passed `--status` 4xx/5xx and no other signal was found |
|
|
144
|
+
|
|
145
|
+
</details>
|
|
146
|
+
|
|
147
|
+
## Check data
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
falseok data today.json --vs yesterday.json
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
<p align="center">
|
|
154
|
+
<picture>
|
|
155
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/terminal-dark.svg">
|
|
156
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/terminal-light.svg" alt="falseok data output: 131 rows instead of 200, 10 duplicates, a block page saved as a row, salary 62% empty" width="880">
|
|
157
|
+
</picture>
|
|
158
|
+
</p>
|
|
159
|
+
|
|
160
|
+
Reads JSON, JSON Lines, CSV and TSV, including what Excel saves on Windows and European semicolon CSVs. Finds lost
|
|
161
|
+
rows, fields that went empty, disappeared or froze on one value, changed types, duplicates, and block-page text that
|
|
162
|
+
got parsed as data. Without `--vs` it checks the file on its own.
|
|
163
|
+
|
|
164
|
+
## In a cron job or CI
|
|
165
|
+
|
|
166
|
+
Exit code `0` = fine, `1` = something is wrong, `2` = the input could not be read.
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
falseok data out/today.jsonl --vs out/last_good.jsonl && cp out/today.jsonl out/last_good.jsonl
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## From Python
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
import falseok
|
|
176
|
+
|
|
177
|
+
r = falseok.check_page(html, status=200) # html can be text or the raw bytes you received
|
|
178
|
+
r = falseok.check_page(resp.content, status=resp.status_code, headers=resp.headers) # headers are optional
|
|
179
|
+
if not r.ok:
|
|
180
|
+
print(r.verdict, r.reason) # captcha robot-check-title (title: "Robot Check")
|
|
181
|
+
|
|
182
|
+
report = falseok.compare(rows_today, rows_yesterday)
|
|
183
|
+
for issue in report.issues:
|
|
184
|
+
print(issue.kind, issue.message)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## How hard we tried to break it
|
|
188
|
+
|
|
189
|
+
- **A stress suite** written to break it: random bytes, 50 MB pages, unclosed tags, every rule's wording hidden in
|
|
190
|
+
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 1,875 tests.
|
|
192
|
+
- **140,000 random inputs** from property-based testing. Nothing broke.
|
|
193
|
+
- **Three fresh sets of pages** from sites it had never seen. The first two showed misses we then fixed, so we don't
|
|
194
|
+
quote them as proof; the third is the benchmark above, scored with the code frozen.
|
|
195
|
+
- **Linux, macOS and Windows, Python 3.10 to 3.14**, on every change.
|
|
196
|
+
|
|
197
|
+
The whole story, failures included: [docs/testing.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/testing.md).
|
|
198
|
+
|
|
199
|
+
## Where the signatures come from
|
|
200
|
+
|
|
201
|
+
Every rule lives in one file, [`src/falseok/signatures.json`](https://github.com/benchmarked-hq/falseok/blob/main/src/falseok/signatures.json): a pattern, where to
|
|
202
|
+
look (title, visible text or raw HTML), and the category. They come from block pages our own production scrapers
|
|
203
|
+
received with `200 OK`, and from the live tests above. The test pages in [`tests/pages`](https://github.com/benchmarked-hq/falseok/blob/main/tests/pages) are rebuilt
|
|
204
|
+
from those cases with identifiers removed.
|
|
205
|
+
|
|
206
|
+
**Seen a block page falseok missed?** Send one entry in `signatures.json` and a small cleaned page in `tests/pages`.
|
|
207
|
+
That's the whole contribution: [docs/contributing.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/contributing.md).
|
|
208
|
+
|
|
209
|
+
## Documentation
|
|
210
|
+
|
|
211
|
+
[Benchmark](https://github.com/benchmarked-hq/falseok/blob/main/docs/benchmark.md) · [How it works](https://github.com/benchmarked-hq/falseok/blob/main/docs/how-it-works.md) · [Verdicts](https://github.com/benchmarked-hq/falseok/blob/main/docs/verdicts.md) ·
|
|
212
|
+
[Data checks](https://github.com/benchmarked-hq/falseok/blob/main/docs/data-checks.md) · [Signatures](https://github.com/benchmarked-hq/falseok/blob/main/docs/signatures.md) · [Testing](https://github.com/benchmarked-hq/falseok/blob/main/docs/testing.md) ·
|
|
213
|
+
[Known limits](https://github.com/benchmarked-hq/falseok/blob/main/docs/limits.md) · [Contributing](https://github.com/benchmarked-hq/falseok/blob/main/docs/contributing.md)
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT. Made by [Benchmarked](https://benchmarked.website): we measure data tools against the most used alternatives on
|
|
218
|
+
price, speed and output.
|
falseok-0.2.0/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/hero-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/hero-light.svg" alt="falseok: catch the 200 OK that isn't" width="880">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
**Your scraper didn't fail. It succeeded at saving a captcha.**
|
|
9
|
+
|
|
10
|
+
`falseok` tells you when a scraped page that came back `200 OK` is really a block, a login wall or an empty shell,
|
|
11
|
+
and when today's dataset quietly broke.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install falseok
|
|
15
|
+
falseok page product.html --status 200
|
|
16
|
+
falseok data today.json --vs yesterday.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Pure Python, zero dependencies, works with whatever fetches your pages. It recognises blocks. It never tries to get
|
|
20
|
+
around them.
|
|
21
|
+
|
|
22
|
+
## Twelve tools, the same saved pages
|
|
23
|
+
|
|
24
|
+
<!-- bench:start -->
|
|
25
|
+
<p align="center">
|
|
26
|
+
<picture>
|
|
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 5,071 saved pages: falseok gave a wrong verdict on 2.5% of them, the next best tool on 8.2%; falseok caught 98.5% of the anti-bot blocks and 76.6% of the unusable 200 OK pages, and flagged 0.7% of the real pages" width="880">
|
|
29
|
+
</picture>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
5,071 pages from sites sampled automatically in 38 languages, fetched once, code frozen before any page was read or any tool was run. Every tool judged the same bytes, with the status code and the response headers. 5,067 pages got a label: 3,494 real, 588 anti-bot blocks, 646 other refusals, 339 empty. 444 of the 1,573 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 5,067.
|
|
33
|
+
|
|
34
|
+
| tool | wrong verdicts | blocks caught | unusable "200 OK" caught | real pages flagged | other refusals caught | empty pages caught | ms per page |
|
|
35
|
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
36
|
+
| **falseok** | **2.5%** | **98.5%** | **76.6%** | 0.7% | **95.0%** | **81.4%** | 1.91 |
|
|
37
|
+
| *Built for the same job* | | | | | | | |
|
|
38
|
+
| a Rust scraper's anti-bot classifier | 15.2% | 91.5% | 45.0% | 0.1% | 14.4% | 52.2% | 1.72 |
|
|
39
|
+
| the blocked-page detector of a popular Python crawler | 15.3% | 91.7% | 45.3% | 0.2% | 14.1% | 52.2% | 3.19 |
|
|
40
|
+
| a new Python response classifier | 22.2% | 61.9% | 21.6% | 0.3% | 1.1% | 25.7% | 57.3 |
|
|
41
|
+
| the most used anti-bot detector, JavaScript | 23.0% | 65.6% | 5.6% | **0.0%** | 0.5% | 5.9% | 2.54 |
|
|
42
|
+
| a Rust challenge detector | 34.3% | 58.5% | 12.4% | 18.3% | 13.8% | 13.0% | 0.21 |
|
|
43
|
+
| *Rules inside scraping frameworks* | | | | | | | |
|
|
44
|
+
| the ban rule of the most used proxy-rotation add-on | 8.2% | 94.0% | 6.1% | **0.0%** | 89.6% | 7.1% | 0.14 |
|
|
45
|
+
| the blocked-request rule of a major crawling framework | 20.2% | 90.1% | 0.2% | **0.0%** | 3.3% | 0.0% | 25.5 |
|
|
46
|
+
| the challenge checks of the most used Cloudflare library | 31.0% | 0.0% | 0.0% | **0.0%** | 0.0% | 0.0% | 0.02 |
|
|
47
|
+
| *One-line checks* | | | | | | | |
|
|
48
|
+
| status-code check (4xx/5xx = bad) | 8.8% | 93.5% | 0.0% | **0.0%** | 89.6% | 0.0% | <0.01 |
|
|
49
|
+
| page-size check (under 10 KB = bad) | 13.3% | 89.1% | 56.1% | 1.1% | 34.5% | 57.2% | <0.01 |
|
|
50
|
+
| keyword search (captcha, blocked, access denied...) | 63.0% | 84.4% | 49.1% | 76.1% | 58.2% | 50.1% | 3.06 |
|
|
51
|
+
|
|
52
|
+
falseok gave a wrong verdict on 2.5% of the labelled pages; the next best tool, the ban rule of the most used proxy-rotation add-on, on 8.2%: **3.3 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
|
+
|
|
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
|
+
|
|
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 (89.6%) and catches no empty page at all.
|
|
57
|
+
|
|
58
|
+
**Where falseok loses: real pages flagged.** It flagged 24 of 3,494 real pages (0.7%). Three tools flagged none, two more flagged a single page. Of the 24: 14 were called empty (real pages with very little text, among them a few search pages with no results), 3 were pages that are a login form, 6 were called a captcha or a challenge, and 1 was a real page its server sent with status `503`. 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 25 of the 444 unusable pages that came back without an error status; falseok caught 340.
|
|
59
|
+
|
|
60
|
+
**What it missed:** 9 of the 588 blocks, all served with status `200`.
|
|
61
|
+
|
|
62
|
+
**Speed:** about 1.3 times faster than the most used JavaScript detector, level with the Rust classifier, about 30.0 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
|
+
<!-- bench:end -->
|
|
64
|
+
|
|
65
|
+
## More than a block detector
|
|
66
|
+
|
|
67
|
+
<!-- more:start -->
|
|
68
|
+
<p align="center">
|
|
69
|
+
<picture>
|
|
70
|
+
<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 100% with the status, empty shells 81.4%, 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
|
+
</picture>
|
|
73
|
+
</p>
|
|
74
|
+
|
|
75
|
+
- **Page not found:** 529 of 529 pages that came back `404` or `410` with the status given, and 408 of 529 from the page alone, when your scraper didn't keep the status.
|
|
76
|
+
- **Empty shells:** 276 of 339 pages that loaded a menu and a footer and nothing else.
|
|
77
|
+
- **Response headers:** pass them (`--headers`, or `headers=` in Python) and it reads the anti-bot service's own
|
|
78
|
+
block marker and names the vendor (4 services so far).
|
|
79
|
+
- **44 languages:** "page not found", "access denied" and the other wording sites write themselves, each phrase
|
|
80
|
+
taken from a page that really came back.
|
|
81
|
+
- **Datasets:** on four real scraped datasets, it caught **1,020 of 1,020** deliberately broken days (lost rows,
|
|
82
|
+
emptied or vanished fields, frozen values, type changes, duplicates, block pages saved as rows) and stayed quiet on
|
|
83
|
+
**200 of 200** healthy ones. A row-count alert, what most pipelines have, caught 240.
|
|
84
|
+
|
|
85
|
+
Three things we learned the hard way:
|
|
86
|
+
|
|
87
|
+
- **Status codes lie.** 444 of the 1573 unusable pages in the benchmark came back without an error status. A status check calls all of them a success.
|
|
88
|
+
- **Grepping for "captcha" flags 76% of real pages** (2660 of 3494). Anti-bot scripts, signup captchas and cookie
|
|
89
|
+
banners load on normal pages too.
|
|
90
|
+
- **Block pages are short. Real pages aren't.** The block pages we measured carry 0 to ~2,000 characters of visible
|
|
91
|
+
text. That one fact does most of the work, and it is also where falseok's few false alarms come from.
|
|
92
|
+
<!-- more:end -->
|
|
93
|
+
|
|
94
|
+
## Check pages
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
falseok page product.html
|
|
98
|
+
falseok page pages/*.html --status 200
|
|
99
|
+
falseok page page.html --headers headers.txt # the response headers, as `curl -D headers.txt` saves them
|
|
100
|
+
falseok page page.html --json
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
<p align="center">
|
|
104
|
+
<picture>
|
|
105
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/verdicts-dark.svg">
|
|
106
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/verdicts-light.svg" alt="Every page gets one verdict: ok, not_html, challenge, captcha, rate_limited, login_wall, consent_wall, soft_block, soft_404, empty_shell, http_error" width="880">
|
|
107
|
+
</picture>
|
|
108
|
+
</p>
|
|
109
|
+
|
|
110
|
+
<details>
|
|
111
|
+
<summary>The verdicts as text</summary>
|
|
112
|
+
|
|
113
|
+
| verdict | what it means |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `ok` | no block signal found |
|
|
116
|
+
| `not_html` | binary or compressed data, not a page |
|
|
117
|
+
| `challenge` | an anti-bot check page (the vendor is named when the HTML shows it) |
|
|
118
|
+
| `captcha` | a captcha in place of the content |
|
|
119
|
+
| `rate_limited` | "too many requests", or HTTP 429 |
|
|
120
|
+
| `login_wall` | you need to sign in to see this |
|
|
121
|
+
| `consent_wall` | a consent page in place of the content |
|
|
122
|
+
| `soft_block` | "access denied", "continue shopping", "something went wrong" served as 200 |
|
|
123
|
+
| `soft_404` | 200, but the page says it does not exist |
|
|
124
|
+
| `empty_shell` | empty response, a saved redirect, or a JavaScript app that never rendered |
|
|
125
|
+
| `http_error` | you passed `--status` 4xx/5xx and no other signal was found |
|
|
126
|
+
|
|
127
|
+
</details>
|
|
128
|
+
|
|
129
|
+
## Check data
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
falseok data today.json --vs yesterday.json
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
<p align="center">
|
|
136
|
+
<picture>
|
|
137
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/terminal-dark.svg">
|
|
138
|
+
<img src="https://raw.githubusercontent.com/benchmarked-hq/falseok/main/assets/terminal-light.svg" alt="falseok data output: 131 rows instead of 200, 10 duplicates, a block page saved as a row, salary 62% empty" width="880">
|
|
139
|
+
</picture>
|
|
140
|
+
</p>
|
|
141
|
+
|
|
142
|
+
Reads JSON, JSON Lines, CSV and TSV, including what Excel saves on Windows and European semicolon CSVs. Finds lost
|
|
143
|
+
rows, fields that went empty, disappeared or froze on one value, changed types, duplicates, and block-page text that
|
|
144
|
+
got parsed as data. Without `--vs` it checks the file on its own.
|
|
145
|
+
|
|
146
|
+
## In a cron job or CI
|
|
147
|
+
|
|
148
|
+
Exit code `0` = fine, `1` = something is wrong, `2` = the input could not be read.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
falseok data out/today.jsonl --vs out/last_good.jsonl && cp out/today.jsonl out/last_good.jsonl
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## From Python
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
import falseok
|
|
158
|
+
|
|
159
|
+
r = falseok.check_page(html, status=200) # html can be text or the raw bytes you received
|
|
160
|
+
r = falseok.check_page(resp.content, status=resp.status_code, headers=resp.headers) # headers are optional
|
|
161
|
+
if not r.ok:
|
|
162
|
+
print(r.verdict, r.reason) # captcha robot-check-title (title: "Robot Check")
|
|
163
|
+
|
|
164
|
+
report = falseok.compare(rows_today, rows_yesterday)
|
|
165
|
+
for issue in report.issues:
|
|
166
|
+
print(issue.kind, issue.message)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## How hard we tried to break it
|
|
170
|
+
|
|
171
|
+
- **A stress suite** written to break it: random bytes, 50 MB pages, unclosed tags, every rule's wording hidden in
|
|
172
|
+
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 1,875 tests.
|
|
174
|
+
- **140,000 random inputs** from property-based testing. Nothing broke.
|
|
175
|
+
- **Three fresh sets of pages** from sites it had never seen. The first two showed misses we then fixed, so we don't
|
|
176
|
+
quote them as proof; the third is the benchmark above, scored with the code frozen.
|
|
177
|
+
- **Linux, macOS and Windows, Python 3.10 to 3.14**, on every change.
|
|
178
|
+
|
|
179
|
+
The whole story, failures included: [docs/testing.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/testing.md).
|
|
180
|
+
|
|
181
|
+
## Where the signatures come from
|
|
182
|
+
|
|
183
|
+
Every rule lives in one file, [`src/falseok/signatures.json`](https://github.com/benchmarked-hq/falseok/blob/main/src/falseok/signatures.json): a pattern, where to
|
|
184
|
+
look (title, visible text or raw HTML), and the category. They come from block pages our own production scrapers
|
|
185
|
+
received with `200 OK`, and from the live tests above. The test pages in [`tests/pages`](https://github.com/benchmarked-hq/falseok/blob/main/tests/pages) are rebuilt
|
|
186
|
+
from those cases with identifiers removed.
|
|
187
|
+
|
|
188
|
+
**Seen a block page falseok missed?** Send one entry in `signatures.json` and a small cleaned page in `tests/pages`.
|
|
189
|
+
That's the whole contribution: [docs/contributing.md](https://github.com/benchmarked-hq/falseok/blob/main/docs/contributing.md).
|
|
190
|
+
|
|
191
|
+
## Documentation
|
|
192
|
+
|
|
193
|
+
[Benchmark](https://github.com/benchmarked-hq/falseok/blob/main/docs/benchmark.md) · [How it works](https://github.com/benchmarked-hq/falseok/blob/main/docs/how-it-works.md) · [Verdicts](https://github.com/benchmarked-hq/falseok/blob/main/docs/verdicts.md) ·
|
|
194
|
+
[Data checks](https://github.com/benchmarked-hq/falseok/blob/main/docs/data-checks.md) · [Signatures](https://github.com/benchmarked-hq/falseok/blob/main/docs/signatures.md) · [Testing](https://github.com/benchmarked-hq/falseok/blob/main/docs/testing.md) ·
|
|
195
|
+
[Known limits](https://github.com/benchmarked-hq/falseok/blob/main/docs/limits.md) · [Contributing](https://github.com/benchmarked-hq/falseok/blob/main/docs/contributing.md)
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
MIT. Made by [Benchmarked](https://benchmarked.website): we measure data tools against the most used alternatives on
|
|
200
|
+
price, speed and output.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "falseok"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Catch the 200 OK that isn't: spot block pages and silently broken scraped data."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{name = "Benchmarked"}]
|
|
13
|
+
keywords = ["scraping", "web-scraping", "captcha", "data-quality", "monitoring", "soft-404"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
19
|
+
"Topic :: Software Development :: Testing",
|
|
20
|
+
]
|
|
21
|
+
dependencies = []
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://benchmarked.website"
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
falseok = "falseok.cli:main"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.package-data]
|
|
30
|
+
falseok = ["signatures.json"]
|
falseok-0.2.0/setup.cfg
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""falseok: catch the 200 OK that isn't."""
|
|
2
|
+
__version__ = "0.2.0"
|
|
3
|
+
|
|
4
|
+
from .data import DataReport, check_rows, compare, load_rows # noqa: E402
|
|
5
|
+
from .page import VERDICTS, PageResult, check_page, decode_html, load_signatures # noqa: E402
|
|
6
|
+
|
|
7
|
+
__all__ = ["check_page", "decode_html", "VERDICTS", "load_signatures", "PageResult", "compare", "check_rows", "load_rows", "DataReport"]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Command line: falseok page ... / falseok data ..."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import csv
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .data import compare, load_rows
|
|
12
|
+
from .page import check_page, decode_html, load_signatures
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _page(args) -> int:
|
|
16
|
+
sigs = load_signatures(args.signatures)
|
|
17
|
+
status = args.status
|
|
18
|
+
if status is not None and not 100 <= status <= 599:
|
|
19
|
+
raise ValueError(f"--status must be between 100 and 599, got {status}")
|
|
20
|
+
headers = None
|
|
21
|
+
if args.headers:
|
|
22
|
+
with open(args.headers, "rb") as f:
|
|
23
|
+
headers = f.read().decode("latin-1")
|
|
24
|
+
if headers.lstrip()[:1] == "{": # a JSON object instead of raw "Name: value" lines
|
|
25
|
+
try:
|
|
26
|
+
headers = json.loads(headers.encode("latin-1").decode("utf-8"))
|
|
27
|
+
except ValueError as e:
|
|
28
|
+
raise ValueError(f"{args.headers}: starts like JSON but is not valid JSON ({e})") from None
|
|
29
|
+
if not isinstance(headers, dict):
|
|
30
|
+
raise ValueError(f"{args.headers}: expected a JSON object of header names and values")
|
|
31
|
+
worst, out, stdin = 0, [], None
|
|
32
|
+
many = len(args.files) > 1
|
|
33
|
+
for path in args.files:
|
|
34
|
+
try:
|
|
35
|
+
if path == "-":
|
|
36
|
+
if stdin is None:
|
|
37
|
+
stdin = sys.stdin.buffer.read()
|
|
38
|
+
data = stdin
|
|
39
|
+
else:
|
|
40
|
+
with open(path, "rb") as f:
|
|
41
|
+
data = f.read()
|
|
42
|
+
except OSError as e:
|
|
43
|
+
print(f"falseok: {path}: {e.strerror or e}", file=sys.stderr)
|
|
44
|
+
worst = 2
|
|
45
|
+
if args.json:
|
|
46
|
+
out.append({"file": path, "verdict": None, "error": e.strerror or str(e)})
|
|
47
|
+
continue
|
|
48
|
+
r = check_page(data, status=status, signatures=sigs, headers=headers) # bytes: the headers may name the charset
|
|
49
|
+
if not r.ok:
|
|
50
|
+
worst = max(worst, 1)
|
|
51
|
+
if args.json:
|
|
52
|
+
out.append({"file": path, **r.to_dict()})
|
|
53
|
+
else:
|
|
54
|
+
who = f" [{r.vendor}]" if r.vendor else ""
|
|
55
|
+
print(f"{path + ': ' if many else ''}{r.verdict}{who}: {r.reason}", flush=True)
|
|
56
|
+
if args.json:
|
|
57
|
+
print(json.dumps(out if many else out[0], indent=2, ensure_ascii=False))
|
|
58
|
+
return worst
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _data(args) -> int:
|
|
62
|
+
rows = load_rows(args.file)
|
|
63
|
+
before = load_rows(args.vs) if args.vs else None
|
|
64
|
+
r = compare(rows, before, max_drop=args.max_drop)
|
|
65
|
+
if args.json:
|
|
66
|
+
print(json.dumps(r.to_dict(), indent=2, ensure_ascii=False, default=str))
|
|
67
|
+
else:
|
|
68
|
+
head = f"{r.rows} rows" + (f" (before: {r.rows_before})" if r.rows_before is not None else "")
|
|
69
|
+
print(("ok: " if r.ok else "PROBLEM: ") + head)
|
|
70
|
+
for i in r.issues:
|
|
71
|
+
print(f" - {i.kind}: {i.message}")
|
|
72
|
+
return 0 if r.ok else 1
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def main(argv=None) -> int:
|
|
76
|
+
p = argparse.ArgumentParser(
|
|
77
|
+
prog="falseok", description="Catch the 200 OK that isn't."
|
|
78
|
+
)
|
|
79
|
+
p.add_argument("--version", action="version", version=f"falseok {__version__}")
|
|
80
|
+
sub = p.add_subparsers(dest="cmd", required=True)
|
|
81
|
+
|
|
82
|
+
pg = sub.add_parser("page", help="is this HTML page real content or a block page?")
|
|
83
|
+
pg.add_argument("files", nargs="+", help="HTML files, or - for stdin")
|
|
84
|
+
pg.add_argument("--status", type=int, help="the HTTP status you got")
|
|
85
|
+
pg.add_argument("--headers", metavar="FILE", help="the response headers you got: a file of 'Name: value' lines "
|
|
86
|
+
"(what `curl -D FILE` saves) or a JSON object")
|
|
87
|
+
pg.add_argument("--signatures", help="use your own signatures JSON file")
|
|
88
|
+
pg.add_argument("--json", action="store_true")
|
|
89
|
+
pg.set_defaults(fn=_page)
|
|
90
|
+
|
|
91
|
+
dt = sub.add_parser("data", help="did this dataset silently break?")
|
|
92
|
+
dt.add_argument("file", help="today's data: .json, .jsonl or .csv")
|
|
93
|
+
dt.add_argument("--vs", help="the last good run, to compare against")
|
|
94
|
+
dt.add_argument("--max-drop", type=float, default=0.2, help="allowed row loss (default 0.2 = 20%%)")
|
|
95
|
+
dt.add_argument("--json", action="store_true")
|
|
96
|
+
dt.set_defaults(fn=_data)
|
|
97
|
+
|
|
98
|
+
args = p.parse_args(argv)
|
|
99
|
+
for stream in (sys.stdout, sys.stderr):
|
|
100
|
+
# A Windows console cannot print every character a page title may hold: replace, never crash.
|
|
101
|
+
try:
|
|
102
|
+
stream.reconfigure(errors="backslashreplace")
|
|
103
|
+
except (AttributeError, ValueError):
|
|
104
|
+
pass
|
|
105
|
+
try:
|
|
106
|
+
return args.fn(args)
|
|
107
|
+
except BrokenPipeError:
|
|
108
|
+
# The reader went away (`falseok ... | head -1`): stop quietly, as other command-line tools do.
|
|
109
|
+
try:
|
|
110
|
+
sys.stdout = open(os.devnull, "w")
|
|
111
|
+
except OSError:
|
|
112
|
+
pass
|
|
113
|
+
return 0
|
|
114
|
+
except (OSError, ValueError, csv.Error) as e:
|
|
115
|
+
print(f"falseok: {e}", file=sys.stderr)
|
|
116
|
+
return 2
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
sys.exit(main())
|