Python client for ZenRows API
Project description
ZenRows Python SDK
SDK to access ZenRows API directly from Python. ZenRows handles proxies rotation, headless browsers, and CAPTCHAs for you.
Installation
Install the SDK with pip.
pip install zenrows
Usage
Start using the API by creating your API Key.
The SDK uses requests for HTTP requests. The client's response will be a requests Response
.
from zenrows import ZenRowsClient
client = ZenRowsClient("YOUR-API-KEY")
url = "https://www.zenrows.com/"
response = client.get(url, params={
# Our algorithm allows to automatically extract content from any website
"autoparse": False,
# CSS Selectors for data extraction (i.e. {"links":"a @href"} to get href attributes from links)
"css_extractor": "",
# Enable Javascript with a headless browser (5 credits)
"js_render": False,
# Use residential proxies (10 credits)
"premium_proxy": False,
# Make your request from a given country. Requires premium_proxy
"proxy_country": "us",
# Wait for a given CSS Selector to load in the DOM. Requires js_render
"wait_for": ".content",
# Wait a fixed amount of time in milliseconds. Requires js_render
"wait": 2500,
# Block specific resources from loading, check docs for the full list. Requires js_render
"block_resources": "image,media,font",
# Change the browser's window width and height. Requires js_render
"window_width": 1920,
"window_height": 1080,
# Will automatically use either desktop or mobile user agents in the headers
"device": "desktop",
# Will return the status code returned by the website
"original_status": False,
}, headers={
"Referrer": "https://www.google.com",
"User-Agent": "MyCustomUserAgent",
})
print(response.text)
You can also pass optional params
and headers
; the list above is a reference. For more info, check out the documentation page.
Sending headers to the target URL will overwrite our defaults. Be careful when doing it and contact us if there is any problem.
Development
Useful commands for development and publishing.
Build
make build
generates the distribution packages. It will not delete previous builds. Remember to change the __version__
before publishing or it will fail.
Clean
make clean
removes previous builds and cache files.
Lint
make lint
runs the linter (flake8
) on the source and test files.
Test
make test
runs all the tests.
Upload to PyPI
python -m twine upload dist/*
uploads the latest build to PyPI. It will upload the whole dist
folder, failing if there was a previous version. Run the clean
command on those cases. Upload attempts of existing versions will fail with a File already exists
error.
For uploading to the test repository, use python -m twine upload --repository testpypi dist/*
. The same restrictions apply.
Contributing
Pull requests are welcome. For significant changes, please open an issue first to discuss what you would like to change.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.