Skip to content

About

Score a rendered web page 0-1 and name why it failed. The scorer behind EnConvert's render_quality. Python + JS, MIT.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

render-quality

render-quality scores a rendered web page from 0 to 1 and names why it lost points: a Cloudflare challenge, a WAF block page, a login wall, an empty or un-hydrated SPA shell, an HTTP error, or a page that says "404" under a 200. It is the scorer behind the render_quality field that EnConvert returns with every web read, extracted into a library so any fetcher (crawl4ai, Firecrawl, Jina Reader, your own Playwright script) can tell a real page from a block page before it reaches an agent, a RAG index or a bill. Python and JavaScript ports, identical output, MIT.

Install

pip install render-quality        # Python 3.10+, depends on beautifulsoup4 only
npm install @enconvert/render-quality   # Node 18+, zero dependencies, ESM and CJS

Use

Python:

from render_quality import QUALITY_FLOOR, score

html = fetch("https://example.com/pricing")          # any fetcher
verdict = score(html, status_code=200)

verdict.render_quality   # 0.35
verdict.is_blocked       # False
verdict.deductions       # {"login_wall": 0.65}
verdict.reasons          # ["login_wall -0.65: auth vocabulary or a password input on a thin page"]

if verdict.is_blocked or verdict.render_quality < QUALITY_FLOOR:
    retry_with_a_browser()

JavaScript / TypeScript:

import { score, QUALITY_FLOOR } from "@enconvert/render-quality";

const response = await fetch("https://example.com/pricing");
const verdict = score(await response.text(), { statusCode: response.status });

verdict.render_quality;  // 0.25
verdict.is_blocked;      // true
verdict.deductions;      // { anti_bot_challenge: 0.6, empty_body: 0.15 }
verdict.reasons;         // ["anti_bot_challenge -0.60: 2+ challenge markers ...", "empty_body -0.15: ..."]

if (verdict.is_blocked || verdict.render_quality < QUALITY_FLOOR) retryWithABrowser();

The Verdict has the same four keys in both languages, and they are the same keys the EnConvert API returns: render_quality, deductions, is_blocked, reasons.

Deductions

The score is 1.0 - sum(deductions), rounded to 4 places and clamped to [0, 1]. A deduction appears in deductions only when it fired.

Deduction Weight Fires when
anti_bot_challenge 0.60 2 or more of 5 challenge markers appear as case-insensitive substrings of the raw HTML: checking your browser, just a moment, ray id, cf-browser-verification, challenge-platform. Raw markup, not visible text, because a Cloudflare interstitial's strongest fingerprints are element ids and script paths.
bot_detection 0.50 2 or more of 11 block-page phrases in the visible text (access denied, bot detected, captcha, hcaptcha, unusual traffic, unusual activity, are you a robot, request blocked, you don't have permission to access, access to this page has been denied, pardon our interruption), or 1 of 5 strong signatures (the request could not be satisfied, attention required! | cloudflare, checking if the site connection is secure, why have i been blocked, please enable cookies and reload the page) on a page under 200 visible words.
login_wall 0.65 Word-boundary hits on 12 auth phrases (sign in, sign up, sign-in, sign-up, signin, signup, log in, log-in, login, create account, create an account, authentication required): 3 or more hits under 200 words, or 2 or more under 120 words, or a visible <input type="password"> under 350 words.
empty_body 0.70 / 0.15 Fewer than 20 visible words (a failed render: challenge stub, empty shell) / fewer than 100 (thin page). Visible words exclude script, style, noscript and template content.
unhydrated_shell 0.70 A framework mount node (#root, #app, #__next, #__nuxt, #___gatsby, [data-reactroot], app-root) holds fewer than 20 words on a page under 500 words, and the hard empty_body tier did not already fire. Catches the SPA shell whose static nav and footer clear the 100-word floor.
http_error 0.70 status_code >= 400. Fires only when you pass the main-document status; None leaves it unfired.
soft_404 0.65 The <title> or first <h1> is a 404 phrase (anchored patterns for 404, 404 Not Found, 404: This page could not be found, Page Not Found | Site, We couldn't find that page, ...), the page has fewer than 250 distinct words, and http_error did not fire. An article titled "Understanding the 404 error" does not match.

Not included: the four runtime deductions

The EnConvert gateway applies four more deductions that need a live browser session and cannot be computed from HTML alone. They are deliberately absent here, so a page that scores 1.0 with this package can still lose up to 0.55 in the hosted API:

Deduction Weight Signal
js_errors 0.20 / 0.10 more than 10 / more than 3 console errors during the render
resource_failures 0.15 / 0.05 more than 10 / more than 3 failed subresource loads
domain_redirect 0.10 the registrable domain (eTLD+1) changed between requested and final URL
slow_render 0.10 / 0.05 page load over 30 s / over 15 s

is_blocked and the 0.40 floor

is_blocked is true when anti_bot_challenge or bot_detection fired. That is the gateway's exact definition: the origin served an interstitial instead of the page.

QUALITY_FLOOR = 0.40. Every weight in the table is sized so that a single detected failure lands the page below it (0.35 for a login wall or soft 404, 0.30 for an empty body, un-hydrated shell or HTTP error, 0.40 or lower for challenges). EnConvert gates on both signals together:

usable = not verdict.is_blocked and verdict.render_quality >= QUALITY_FLOOR

The floor exists because a page can be useless without being blocked (an empty shell) and blocked without being empty (a challenge page that carries site chrome). A page at exactly 0.40 clears the floor. The one honest false alarm in the corpus, a security article that quotes Cloudflare's challenge text, scores 0.40 but is still rejected by the gate, because anti_bot_challenge sets is_blocked.

Adapters

from render_quality import from_crawl4ai, from_firecrawl, from_jina

from_crawl4ai(result)               # crawl4ai CrawlResult: html, status_code
from_firecrawl(scrape_json)         # Firecrawl scrape response (envelope or data): rawHtml or html,
                                    #   metadata.statusCode; markdown-only falls back to text
from_jina(markdown, status_code)    # Jina Reader output (markdown only, see below)
import { fromCrawl4ai, fromFirecrawl, fromJina } from "@enconvert/render-quality";

from_firecrawl prefers rawHtml over html: Firecrawl's html is a cleaned copy that drops the scripts and chrome the markup checks read.

Markdown-only input

Jina Reader (and Firecrawl without an HTML format) hands back markdown, so there is no DOM to inspect. from_jina routes through score_text / scoreText, which runs every text-based rule (challenge and block phrases, login vocabulary, word counts, http_error, and soft_404 via a leading Title: line or the first # heading) and skips the two structural ones (unhydrated_shell and the password-input branch of login_wall). The verdict says so with a trailing html_unavailable: ... entry in reasons.

Adding an adapter

An adapter maps two things and calls score: the rendered HTML and the main-document status code. A few lines:

def from_playwright(page, response) -> Verdict:
    return score(
        page.content(),
        status_code=response.status if response else None,
    )

If the fetcher only gives you text, call score_text instead. Pull requests for adapters are welcome; keep them field mapping only, the rules live in scorer.

Hosted reference implementation

EnConvert runs this scorer on every page its web reading API returns, and enforces it rather than only reporting it:

  • The render ladder. A page is fetched first over plain TLS with browser fingerprints, then in Chromium, then in stealth Chromium. The scorer decides whether to escalate: a rung whose result is blocked or under the floor hands the URL to the next one. Real 404s and 410s stop the ladder.
  • Blocked reads are not billed. A read that comes back is_blocked, or whose deductions include http_error or login_wall, costs nothing; the response carries billed: false alongside render_quality, deductions and status_code. Ingest skips and unbills every page under 0.40.
  • The weekly benchmark. A public corpus of bot-gated, paywalled and JS-heavy homepages is re-run against the API, with the flag-correctness and recovery rates published each week.

Docs and API reference: https://enconvert.com

Parity between the two ports and the gateway

fixtures/corpus/ holds 54 pages (EnConvert's 50-page F.7 validation corpus plus 4 synthetic pages for unhydrated_shell, soft_404, the password-input login path, and a parser stress page tuned to sit one word under the 100-word threshold). fixtures/expected.json is generated from the Python package by fixtures/regen_expected.py; both test suites assert against it, so the ports cannot drift apart unnoticed. The Python suite also imports the gateway scorer when a gateway checkout is present and checks deductions and scores to 1e-9.

The JavaScript port has no dependencies. Its HTML tokenizer mirrors BeautifulSoup's html.parser tree building (end tags pop to the nearest open tag of that name, void elements, the HTML5 entity table with bs4's windows-1252 quirk for numeric references under 256, text node boundaries at tags, comments and CDATA) closely enough that every fixture scores identically. Exotic malformed markup can still parse differently; if you find a page where the two ports disagree, open an issue with the HTML.

# Python
cd python && python -m pytest -q
# JavaScript
cd js && npm install && npm test
# Regenerate the golden file after a deliberate scorer change
python fixtures/regen_expected.py

License

MIT. See LICENSE.

About

Score a rendered web page 0-1 and name why it failed. The scorer behind EnConvert's render_quality. Python + JS, MIT.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages