Real browsers. Structured extraction. Screenshots and automation.
Turn a URL into rendered HTML, readable Markdown, structured data, or a PNG screenshot. Connect a remote browser with Playwright when your workflow needs interaction.
Website · API documentation · Get an API key · 中文
- Python 3.9+ with synchronous and asynchronous clients.
- Zero runtime dependencies; uses the Python standard library.
- Explicit request timeouts, response validation, and typed errors.
- No automatic retries of metered requests or browser creation.
Use 0.2.0 or newer for the current screenshot, JSON and cloud-browser contracts. Upgrading from 0.1.0? Read the migration guide.
pip install adscrawlCreate an account, create an API key, and set ADSCRAWL_API_KEY in the server environment.
from adscrawl import AdsCrawl
client = AdsCrawl()
markdown = client.markdown({
"url": "https://www.adscrawl.net",
"waitUntil": "domcontentloaded",
})
print(markdown)You can also use AdsCrawl(api_key="..."). Keep API keys in server-side code. Request dictionaries use the same camelCase fields as the HTTP API and TypeScript SDK.
from pathlib import Path
from adscrawl import AdsCrawl
client = AdsCrawl()
html = client.html({"url": "https://www.adscrawl.net"})
article = client.json({"url": "https://www.adscrawl.net"})
print(article)
png = client.screenshot({
"url": "https://www.adscrawl.net",
"viewport": {"width": 1440, "height": 900},
"fullPage": True,
"waitUntil": "load",
})
Path("page.png").write_bytes(png)html() returns HTML by default. markdown() returns Markdown, article() returns a dictionary, and screenshot() returns PNG bytes. Use a custom proxy or managed countryCode; they cannot be combined.
AdsCrawl uses real browsers with configurable routing and browser fingerprints. This example uses managed GLOBAL routing unless proxy environment variables are present, opens BrowserScan, and saves the returned screenshot. The same browser workflow can access and render Pixelscan and IPhey; inspect the returned page for its current score.
import os
from pathlib import Path
from adscrawl import AdsCrawl
client = AdsCrawl()
server = os.getenv("ADSCRAWL_PROXY_SERVER")
username = os.getenv("ADSCRAWL_PROXY_USERNAME")
password = os.getenv("ADSCRAWL_PROXY_PASSWORD")
if bool(username) != bool(password):
raise RuntimeError("Set both proxy username and password, or neither.")
if not server and (username or password):
raise RuntimeError("Set ADSCRAWL_PROXY_SERVER with proxy credentials.")
routing = {"countryCode": "GLOBAL"}
if server:
proxy = {"server": server}
if username and password:
proxy.update({"username": username, "password": password})
routing = {"proxy": proxy}
png = client.screenshot({
"url": "https://www.browserscan.net/",
**routing,
"viewport": {"width": 1440, "height": 900},
"fullPage": True,
"waitUntil": "networkidle",
"timeoutMs": 60_000,
"userAgentMode": "random",
"userAgentOs": "windows",
"fingerprint": {
"webRtc": "forward", "webGl": "random", "webGpu": "random",
"webGlImage": "random", "canvas": "random",
"audioContext": "random", "clientRects": "random",
"speechVoices": "random", "fonts": "random",
"hardware": "random", "doNotTrack": "random",
},
}, timeout_ms=100_000)
Path("browserscan.png").write_bytes(png)from adscrawl import AdsCrawl
client = AdsCrawl()
print(client.spa.templates()["templates"])
result = client.spa.extract({
"url": "https://www.adscrawl.net",
"fields": {
"title": {"source": "dom", "selector": "h1", "value": "text", "required": True},
},
})
print(result["data"]["title"], result["missingFields"])
inspection = client.spa.inspect({"url": "https://www.adscrawl.net"})
print(inspection["candidates"])pip install "adscrawl[playwright]"
playwright install chromiumfrom adscrawl import AdsCrawl
from playwright.sync_api import sync_playwright
client = AdsCrawl()
session = client.cdp.create({
"idleTimeoutMs": 600_000,
"maxSessionMs": 3_600_000,
"browserSettings": {"viewport": {"width": 1440, "height": 900}},
})
try:
with sync_playwright() as playwright:
browser = playwright.chromium.connect_over_cdp(session["cdpBaseUrl"])
context = browser.contexts[0]
page = context.pages[0] if context.pages else context.new_page()
page.goto("https://www.adscrawl.net")
print(page.title())
browser.close()
finally:
client.cdp.close(session["sessionId"])cdp.list() returns {"ok": true, "data": [...]}. cdp.get_version(session) discovers the WebSocket endpoint without forwarding the API key. Connection URLs contain secrets and should not be logged.
Create a saved profile, then start it with empty options. Put proxy, cookies and fingerprint settings in browserSettings on create/update. The removed launch operation now raises a migration error before making a request.
The start response can include both a signed CDP URL and an owner-authenticated Live URL. If cdpBaseUrl is null, inspect cdpErrorCode and request a new endpoint; do not start another browser. Open Live privately to watch the Agent, complete login or verification, and intervene. Closing Live or CDP does not stop the runtime.
A stopping response is pending: poll the profile until stopped. Stop retains the profile; delete requires a stopped profile. List and detail responses are summaries and do not guarantee browserSettings.
See the complete create/start/confirmed-stop example and 0.2 migration guide for filters, CDP endpoint, file leases and multi-format capture.
import asyncio
from adscrawl import AsyncAdsCrawl
async def main():
async with AsyncAdsCrawl() as client:
markdown = await client.markdown({"url": "https://www.adscrawl.net"})
print(markdown)
asyncio.run(main())The async facade runs the dependency-free standard-library HTTP transport in worker threads. Cancelling a coroutine or reaching a timeout does not prove remote browser work stopped.
from adscrawl import AdsCrawl, AdsCrawlAPIError, AdsCrawlTimeoutError
client = AdsCrawl(base_url="https://api.adscrawl.net", timeout_ms=160_000)
try:
text = client.markdown(
{"url": "https://www.adscrawl.net", "timeoutMs": 60_000},
timeout_ms=100_000,
)
print(text)
except AdsCrawlAPIError as error:
print(error.status, error.code, error.trace_id)
except AdsCrawlTimeoutError:
print("Inspect remote sessions before retrying.")The API key defaults to ADSCRAWL_API_KEY; the base URL defaults to ADSCRAWL_BASE_URL, ADSCRAWL_API_URL, then https://api.adscrawl.net. Errors include AdsCrawlAPIError, AdsCrawlTimeoutError, AdsCrawlConnectionError, and AdsCrawlResponseError. API response bodies are credential-redacted. Requests are not automatically retried.
python -m unittest discover -s tests -v
python -m build
python -m twine check dist/*Tests use fake responses and never consume AdsCrawl credits. See RELEASING.md for PyPI trusted publishing.
MIT