langchain-zenrows
The langchain-zenrows integration tool enables LangChain agents to scrape and access web content at any scale using Zenrows' enterprise-grade infrastructure.
Whether you need to scrape JavaScript-heavy single-page applications, bypass anti-bot systems, access geo-restricted content, or extract structured data at scale, this integration provides the tools and reliability needed for modern AI applications.
Table of Contents
Installation
pip install langchain-zenrows
Usage
To use the Zenrows Fetch with LangChain, you'll need a Zenrows API key. You can sign up for free at Zenrows.
For more comprehensive examples and use cases, see the
examples/folder.
Renamed: this tool was previously exported as
ZenRowsUniversalScraper. That name still works (it's a deprecated alias that redirects toZenrowsFetchand will keep working until removed in a future release), but new code should importZenrowsFetch.
Basic Usage
import os
from langchain_zenrows import ZenrowsFetch
# Set your Zenrows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"
# Initialize the tool
scraper = ZenrowsFetch()
# Scrape a simple webpage
result = scraper.invoke({"url": "https://httpbin.io/html"})
print(result)
Advanced Usage with Parameters
import os
from langchain_zenrows import ZenrowsFetch
# Set your Zenrows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"
scraper = ZenrowsFetch()
# Scrape with JavaScript rendering and premium proxies
result = scraper.invoke({
"url": "https://www.scrapingcourse.com/ecommerce/",
"js_render": True,
"premium_proxy": True,
"proxy_country": "us",
"response_type": "markdown",
"wait": 2000 # Wait 2 seconds after page load
})
print(result)
See the API Reference section below for more available parameters and customizing scraping requests.
Using with LangChain Agents
from langchain_zenrows import ZenrowsFetch
from langchain_openai import ChatOpenAI # or your preferred LLM
from langgraph.prebuilt import create_react_agent
import os
# Set your Zenrows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"
os.environ["OPENAI_API_KEY"] = "<YOUR_OPEN_AI_API_KEY>"
# Initialize components
llm = ChatOpenAI(model="gpt-4o-mini")
zenrows_tool = ZenrowsFetch()
# Create agent
agent = create_react_agent(llm, [zenrows_tool])
# Use the agent
result = agent.invoke(
{
"messages": "Scrape https://news.ycombinator.com/ and list the top 3 stories with title, points, comments, username, and time."
}
)
print("Agent Response:")
for message in result["messages"]:
print(f"{message.content}")
CSS Extraction
Extract specific data using CSS selectors:
import json
import os
from langchain_zenrows import ZenrowsFetch
# Set your Zenrows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"
scraper = ZenrowsFetch()
# Extract specific elements
css_selector = json.dumps({
"title": "h1",
"paragraphs": "p"
})
result = scraper.invoke({
"url": "https://httpbin.io/html",
"css_extractor": css_selector
})
Premium Proxy with Geo-targeting
Access geo-restricted content:
import os
from langchain_zenrows import ZenrowsFetch
# Set your Zenrows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"
scraper = ZenrowsFetch()
# Check your IP location
result = scraper.invoke({
"url": "https://httpbin.io/ip",
"premium_proxy": True,
"proxy_country": "us"
})
print(result) # Shows the US IP being used
Extract - structured data without CSS selectors
ZenrowsExtract uses AI to return structured data instead of raw HTML. It's a
separate tool from ZenrowsFetch with its own, leaner input schema - options
that Fetch supports but Extract's server ignores (autoparse, css_extractor,
response_type, outputs) aren't offered here at all, so there's nothing to
set that silently does nothing. The result is JSON with parsed (the
structured data) and html (the raw page, included during beta):
import json
import os
from langchain_zenrows import ZenrowsExtract
# Set your Zenrows API key
os.environ["ZENROWS_API_KEY"] = "<YOUR_ZENROWS_API_KEY>"
extractor = ZenrowsExtract()
result = extractor.invoke({"url": "https://www.scrapingcourse.com/ecommerce/"})
data = json.loads(result)
print(data["parsed"])
See the Extract docs for details on
what parsed looks like for different page types.
Autoparse fallback: extract="auto" (the default) is a domain-gated open
beta - if the target site isn't enabled yet, Zenrows returns an AUTH010
error. By default, ZenrowsExtract catches that and retries once with the
general-purpose Autoparse feature instead of raising, matching the CLI's
zenrows extract behavior. The result is re-wrapped into the same
{"parsed": ..., "html": ...} shape, plus extract_fallback: "autoparse" so
you can tell a fallback happened:
data = json.loads(result)
if data.get("extract_fallback"):
print("This domain isn't in the Extract beta yet - used Autoparse instead.")
print(data["parsed"])
Pass fallback_to_autoparse=False to disable this and always raise on
AUTH010 instead.
API Reference
ZenrowsFetch
Main tool class for web scraping with Zenrows.
Parameters:
zenrows_api_key(str, optional): Your Zenrows API key. If not provided, looks forZENROWS_API_KEYenvironment variable.
Input Schema:
For complete parameter documentation and details, see the official Zenrows API Reference.
| Parameter | Type | Description |
|---|---|---|
url |
str | Required. The URL to scrape |
adaptive_stealth |
bool | Adaptive Stealth Mode (sent as mode="auto"): Zenrows starts with the cheapest viable setup and escalates to js_render/premium_proxy only when needed, billing only for the configuration that succeeds. Setting js_render, premium_proxy, or a browser-only option (wait_for, wait, js_instructions, screenshots, json_response) uses that fixed configuration instead (default: True) |
mode |
str | Set to "auto" to require Adaptive Stealth Mode even with browser-only options. Can't be combined with js_render or premium_proxy |
js_render |
bool | Enable JavaScript rendering with a headless browser. Essential for modern web apps, SPAs, and sites with dynamic content (default: False) |
js_instructions |
str | Execute custom JavaScript on the page to interact with elements, scroll, click buttons, or manipulate content |
premium_proxy |
bool | Use residential IPs to bypass anti-bot protection. Essential for accessing protected sites (default: False) |
proxy_country |
str | Set the country of the IP used for the request. Use for accessing geo-restricted content. Two-letter country code. Works with Adaptive Stealth Mode; otherwise Premium Proxies are enabled for it |
session_id |
int | Maintain the same IP for multiple requests for up to 10 minutes. Essential for multi-step processes |
custom_headers |
dict | Include custom headers in your request to mimic browser behavior |
wait_for |
str | Wait for a specific CSS Selector to appear in the DOM before returning content |
wait |
int | Wait a fixed amount of milliseconds after page load |
block_resources |
str | Block specific resources (images, fonts, etc.) from loading to speed up scraping |
response_type |
str | Convert HTML to other formats. Options: "markdown", "plaintext", "pdf" |
css_extractor |
str | Extract specific elements using CSS selectors (JSON format) |
autoparse |
bool | Automatically extract structured data from HTML (default: False) |
screenshot |
str | Capture an above-the-fold screenshot of the page (default: "false") |
screenshot_fullpage |
str | Capture a full-page screenshot (default: "false") |
screenshot_selector |
str | Capture a screenshot of a specific element using CSS Selector |
screenshot_format |
str | Choose between "png" (default) and "jpeg" formats for screenshots |
screenshot_quality |
int | For JPEG format, set quality from 1 to 100. Lower values reduce file size but decrease quality |
original_status |
bool | Return the original HTTP status code from the target page (default: False) |
allowed_status_codes |
str | Returns the content even if the target page fails with specified status codes. Useful for debugging or when you need content from error pages |
json_response |
bool | Capture network requests in JSON format, including XHR or Fetch data. Ideal for intercepting API calls made by the web page (default: False) |
outputs |
str | Specify which data types to extract from the scraped HTML. Accepted values: emails, phone_numbers, headings, images, audios, videos, links, menus, hashtags, metadata, tables, favicon |
ZenrowsExtract
Tool class for AI-powered structured extraction (beta). Same zenrows_api_key parameter as ZenrowsFetch. Returns JSON (parsed + html) instead of raw HTML/Markdown.
For complete details, see the official Extract docs.
| Parameter | Type | Description |
|---|---|---|
url |
str | Required. The URL to extract data from |
extract |
str | Extraction mode: "auto" (default), "native", or "standard" |
js_render |
bool | Enable JavaScript rendering with a headless browser (default: False) |
premium_proxy |
bool | Use residential IPs to bypass anti-bot protection (default: False) |
proxy_country |
str | Two-letter country code for the request's IP. Works with Adaptive Stealth Mode; otherwise Premium Proxies are enabled for it |
session_id |
int | Maintain the same IP for multiple requests for up to 10 minutes |
custom_headers |
dict | Include custom headers in your request |
wait_for |
str | Wait for a specific CSS Selector to appear before returning content |
wait |
int | Wait a fixed amount of milliseconds after page load |
block_resources |
str | Block specific resources (images, fonts, etc.) from loading |
original_status |
bool | Return the original HTTP status code from the target page (default: False) |
allowed_status_codes |
str | Return content even if the target page fails with the specified status codes |
fallback_to_autoparse |
bool | Retry once with Autoparse if extract="auto" hits a domain Extract isn't available for yet, REQS007 or AUTH010 (default: True) |
adaptive_stealth |
bool | Send Adaptive Stealth Mode (mode="auto") so a target needing js_render/premium_proxy escalates automatically instead of failing with REQS002. Setting js_render, premium_proxy, wait, or wait_for uses that fixed configuration instead (default: True) |
Not offered here - the server ignores these when extract is set, so they aren't in this schema: autoparse, css_extractor, response_type, outputs.
Features
- JavaScript Rendering: Scrape modern SPAs and dynamic content
- Anti-Bot Bypass: Bypass sophisticated bot detection systems
- Geo-Targeting: Access region-specific content with 190+ countries
- Multiple Output Formats: HTML, Markdown, Plaintext, PDF, Screenshots
- CSS Extraction: Target specific data with CSS selectors
- AI-Powered Extraction (beta): Structured data without writing selectors, via
ZenrowsExtract - Structured Data Extraction: Automatically extract emails, phone numbers, links, and other data types
- Session Management: Maintain consistent sessions across requests
- Wait Conditions: Smart waiting for dynamic content
- Premium Proxies: 55M+ residential IPs for maximum success rates
License
langchain-zenrows is distributed under the terms of the MIT license.
Support
Metadata
Release files for langchain-zenrows 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_zenrows-0.3.0.tar.gz | 17.3 kB | Without provenance | Details for langchain_zenrows-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_zenrows-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_zenrows-0.3.0-py3-none-any.whl |
Total release size: 35.1 kB
Release files / langchain_zenrows-0.3.0.tar.gz
| Download URL | langchain_zenrows-0.3.0.tar.gz |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20caab79edf791c5e00e8a4b2f7bf31a518a7d9eaf3927c3355f0291d7fda9e6
|
|
BLAKE2b-256 checksum How to use checksums |
d39c3036527ce549b78835eca22b8464de026d80c2858249bd91d1520434e72f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.4
|
Release files / langchain_zenrows-0.3.0-py3-none-any.whl
| Download URL | langchain_zenrows-0.3.0-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d57e076484a2c2586d59b88c365376ae2841eb37105c1c4a5e3abaf7caa383f
|
|
BLAKE2b-256 checksum How to use checksums |
0f2f14240229448e2995fdd237cbf75cac29c6041f79d3d3d89d241c693f6efe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.4
|
Security for langchain-zenrows 0.3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.