ZenRows Python SDK

1.4.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →