Skip to main content

scrapy-adscrawl

An opt-in Scrapy downloader middleware that sends selected GET requests to AdsCrawl's POST /html API and returns the rendered HTML as a Scrapy HtmlResponse. This is a small adapter for pages where browser-rendered DOM is useful; it does not replace Scrapy's scheduler, selectors, pipelines, or spider logic.

This is an independent community integration maintained by AdsCrawl. It is not an official Scrapy project or an upstream Scrapy add-on listing.

Install

Requires Python 3.11+ and Scrapy 2.20+.

python -m pip install "git+https://github.com/AdsCrawl/scrapy-adscrawl.git"

Set your API key in the process environment. Do not commit it in settings.py, a spider, or a workflow:

export ADSCRAWL_API_KEY="YOUR_ADSCRAWL_API_KEY"

Enable the middleware in your Scrapy project settings:

DOWNLOADER_MIDDLEWARES = {
    "scrapy_adscrawl.middleware.AdsCrawlDownloaderMiddleware": 543,
}

It is opt-in per request. Requests without meta["adscrawl"] continue through Scrapy's normal downloader:

import scrapy


class ExampleSpider(scrapy.Spider):
    name = "example"
    custom_settings = {"ROBOTSTXT_OBEY": True}

    async def start(self):
        yield scrapy.Request(
            "https://example.com/",
            meta={
                "adscrawl": {
                    "wait_until": "domcontentloaded",
                    "selector": "main",
                    "timeout_ms": 60_000,
                },
                # Give the AdsCrawl API call enough time to complete.
                "download_timeout": 90,
            },
            callback=self.parse,
        )

    def parse(self, response):
        yield {"title": response.css("h1::text").get(), "html": response.text}

Supported meta["adscrawl"] options are:

  • selector: optional CSS selector to wait for and extract.
  • wait_until: domcontentloaded, load, or networkidle.
  • timeout_ms: positive integer, at most 3_600_000.

The adapter sends only the target URL and these options to the fixed AdsCrawl API endpoint. It does not forward Scrapy request headers, authorization, cookies, or request bodies. Only HTTP/HTTPS targets on ports 80 or 443 are accepted; embedded URL credentials, obvious local/internal hostnames, and non-public IP literals are rejected. This local check is not a substitute for server-side URL policy, and the middleware should not be given untrusted target URLs without your own controls.

Cost, retries, and response behavior

Every opted-in request makes one AdsCrawl HTML API call. AdsCrawl documents that one credit is consumed after request validation and before the task is enqueued. The adapter disables transparent retries and caching for the opted-in request and for its internal API request, to reduce accidental duplicate calls. If a request times out after AdsCrawl accepted it, the result may be uncertain; the adapter deliberately does not retry it automatically.

A successful call becomes an HtmlResponse with status 200 and the original Scrapy request URL. AdsCrawl's HTML endpoint returns rendered HTML, but does not provide the target's original HTTP status, response headers, cookies, or final redirect URL in that response. Therefore this adapter does not reproduce those HTTP semantics. Non-200 AdsCrawl API replies become AdsCrawlAPIError exceptions; their message includes only the status and a validated API error code, not the API body or key.

Scrapy's robots middleware runs before this adapter at the recommended priority; with ROBOTSTXT_OBEY = True, the usual robots.txt check remains in place. The internal request to api.adscrawl.net skips robots checks, cookies and caching, and uses a separate API download slot. Remote rendering also means Scrapy's per-target-domain download delay, concurrency, and AutoThrottle are not equivalent to throttling requests made directly to each target. Plan AdsCrawl credit usage and concurrency explicitly. Custom middlewares also see internal API requests; audit middleware that logs or changes headers, proxies, or download slots before enabling this adapter.

See the AdsCrawl HTML API documentation for the full service contract and pricing/credit details.

Tutorial

See Render only the JavaScript-heavy pages in a Scrapy crawl for a step-by-step guide, a runnable Quotes to Scrape spider, and offline tests. The tutorial starts by checking whether Scrapy can use the site's data source directly, then opts selected requests into rendered HTML only when that is useful.

Tests

The suite includes isolated middleware unit tests and an integration test using Scrapy's real crawler/engine with fake HTTP download handlers. Network sockets are disabled (local Unix sockets are allowed for asyncio). It does not use a real AdsCrawl API key or visit AdsCrawl or target sites; this is not a production end-to-end service test.

python -m pip install -e ".[test,lint]"
python -m pytest --disable-socket --allow-unix-socket
python -m ruff check .
python -m ruff format --check .
python -m pip check

License

MIT. See LICENSE.

Metadata

Release files for scrapy-adscrawl 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrapy-adscrawl 0.1.0
File Size Uploaded Provenance Actions
scrapy_adscrawl-0.1.0.tar.gz 11.9 kB With provenance Details for scrapy_adscrawl-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scrapy-adscrawl 0.1.0
File Interpreter ABI Platform Actions
scrapy_adscrawl-0.1.0-py3-none-any.whl Python 3 none any Details for scrapy_adscrawl-0.1.0-py3-none-any.whl

Total release size: 19.8 kB

Release files / scrapy_adscrawl-0.1.0.tar.gz

Download URL scrapy_adscrawl-0.1.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
056ca11b81ccf48569dc5653e3b6a9ad1a82a2f4f41d3182ccd1b47dcda01c56
BLAKE2b-256 checksum
How to use checksums
c86677834404280b4280c488d11159e9fc4b854d8a0f82a44d69af430d08730f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / scrapy_adscrawl-0.1.0-py3-none-any.whl

Download URL scrapy_adscrawl-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a8ceb29d89393089ae586d090b867b0abe5ee7681ff4d30679c4742d14c2ed3
BLAKE2b-256 checksum
How to use checksums
79b59c82221a4cc230a0ee750d0fcae8535296cb6f60e0d7d195c9f12dd5f604
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for scrapy-adscrawl 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for scrapy_adscrawl-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page