Registry / http-networking / zenrows

zenrows

JSON →
library1.4.0pypypi✓ verified 85d ago

ZenRows is a Python client for the ZenRows API, designed to simplify web scraping by automatically handling challenges like proxy rotation, CAPTCHA solving, and JavaScript rendering. It enables users to extract data from complex, anti-bot protected websites. The library is actively maintained, currently at version 1.4.0, with regular updates to its API and SDKs.

pip install zenrows
INSTALL
IMPORT
SIG · ZENROWS
Z
zenrows
http-networkingpythonv1.4.0
Install
2.1s avg
Import
730ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.777s · 21.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.1s · import 0.682s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ZenRowsClient
from zenrows import ZenRowsClient
import zenrows
The primary interaction is through the 'ZenRowsClient' class, not the top-level 'zenrows' module directly.

This quickstart demonstrates how to initialize the ZenRows client with an API key (preferably from an environment variable) and make a basic GET request to a target URL, enabling common features like JavaScript rendering and premium proxies. The response object is a standard `requests.Response` object.

import os from zenrows import ZenRowsClient # Get your API key from environment variable for security ZENROWS_API_KEY = os.environ.get('ZENROWS_API_KEY', 'YOUR_ZENROWS_API_KEY') if not ZENROWS_API_KEY or ZENROWS_API_KEY == 'YOUR_ZENROWS_API_KEY': print("Warning: ZENROWS_API_KEY environment variable not set or is default. Please replace with your actual API key.") # Exit or raise error in production code client = ZenRowsClient(ZENROWS_API_KEY) # Make a GET request to a target URL with JavaScript rendering enabled target_url = 'https://www.example.com' response = client.get(target_url, params={'js_render': 'true', 'premium_proxy': 'true'}) if response.status_code == 200: print(f"Successfully scraped {target_url}. Partial content:\n{response.text[:500]}...") else: print(f"Failed to scrape {target_url}. Status code: {response.status_code}, Error: {response.text}")
Debug
Known issues
gotchaRetries are not active by default. You must explicitly specify the `retries` parameter when initializing `ZenRowsClient` if you want automatic retries for failed requests (e.g., 429, 5xx errors).
fix
Initialize client with `client = ZenRowsClient('YOUR-API-KEY', retries=3)`.
affects: All versions
gotchaWhen performing asynchronous requests, ensure you use `client.get_async` (or `post_async`, etc.) and run your async function with `asyncio.run()`, otherwise, coroutine errors will occur.
fix
Wrap async calls in an `async def main():` and execute with `asyncio.run(main())`.
affects: All versions
gotchaSending custom headers to the target URL might overwrite ZenRows' default headers, potentially leading to increased detection or blocking.
fix
Be cautious with custom headers; only send them if necessary and test thoroughly. Contact ZenRows support if issues arise.
affects: All versions
gotchaUsing the `css_extractor` parameter is often more efficient than fetching the entire HTML and then parsing it with libraries like BeautifulSoup, especially for large responses or limited bandwidth.
fix
Pass a dictionary of CSS selectors to the `css_extractor` parameter: `params={'css_extractor': {'title': 'h1', 'links': 'a @href'}}`.
affects: All versions
gotchaThe ZenRows API key is essential for authentication and usage tracking. Exposing it directly in code or public repositories is a security risk.
fix
Always store your API key securely, preferably in an environment variable (`ZENROWS_API_KEY`) and load it at runtime.
affects: All versions
Errors
Common errors & fixes
coroutine 'main' was never awaited
Attempting to call an asynchronous method (e.g., `client.get_async`) without properly awaiting it or running it within an `asyncio` event loop.
fix
If using `async` methods, define an `async def main():` function containing your async calls and run it with `asyncio.run(main())`.
HTTP Error 429: Too Many Requests
You have exceeded your account's concurrent request limit or rate limit.
fix
Implement retry logic with exponential backoff (using the `retries` parameter) or reduce your concurrency. Check your ZenRows dashboard for plan limits.
HTTP Error 422: Unprocessable Entity
The anti-bot protection on the target website is blocking your request. This often indicates ZenRows couldn't bypass the protection with the current parameters.
fix
Enable `js_render: true`, `premium_proxy: true`, or add a `referer` header. You might also need to use `wait_for` or `wait` parameters for dynamically loaded content.
Incorrect Credentials / Connection Refused (when using direct proxy setup)
Using an incorrect API key, username, password, or proxy host/port when configuring proxies directly (not using the SDK client).
fix
Verify your ZenRows API key and proxy credentials from your dashboard. Ensure the proxy URL format is `http://username:password@proxy-host:port` and the protocol/port match (e.g., 1337 for HTTP, 1338 for HTTPS).
Upgrade
Version history
1.4.0latest on PyPI · released Nov 13, 2024
Audit
Dependencies
requestsrequiredUsed internally by the SDK for HTTP requests and often directly by users for integration with other scraping tools.
urllib3requiredHandles connection pooling and retries; a dependency of requests.
asynciooptionalUsed for concurrent (asynchronous) requests.
Agent activity
41 hits · last 30 days
node
36
OpenAI (training)
1
Resources