Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SDK to access ZenRows API directly from Python. We handle proxies rotation, headless browsers and CAPTCHAs for you.

License

NotificationsYou must be signed in to change notification settings

ZenRows/zenrows-python-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDK to accessZenRows 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 bycreating your API Key.

The SDK usesrequests for HTTP requests. The client's response will be a requestsResponse.

It also usesRetry to automatically retry failed requests (status codes 429, 500, 502, 503, and 504). Retries are not active by default; you need to specify the number of retries, as shown below. It already includes an exponential back-off retry delay between failed requests.

fromzenrowsimportZenRowsClientclient=ZenRowsClient("YOUR-API-KEY",retries=1)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 optionalparams andheaders; the list above is a reference. For more info, check outthe 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.

POST Requests

The SDK also offers POST requests by calling theclient.post method. It can receive a new parameterdata that represents the data sent in, for example, a form.

fromzenrowsimportZenRowsClientclient=ZenRowsClient("YOUR-API-KEY",retries=1)url="https://httpbin.org/anything"response=client.post(url,data={"key1":"value1","key2":"value2",})print(response.text)

PUT Requests

The SDK also offers PUT requests by calling theclient.put method. It can receive a new parameterdata that represents the data sent in, for example, a form.

fromzenrowsimportZenRowsClientclient=ZenRowsClient("YOUR-API-KEY",retries=1)url="https://httpbin.org/anything"response=client.put(url,data={"key1":"value1","key2":"value2",})print(response.text)

Concurrency

To limit the concurrency, it usesasyncio, which will simultaneously send a maximum of requests. The concurrency is determined by the plan you are in, so take a look at thepricing and set it accordingly. Take into account that each client instance will have its own limit, meaning that two different scripts will not share it, and 429 (Too Many Requests) errors might arise.

The main difference with the sequential snippet above isclient.get_async instead ofclient.get. The rest will work exactly the same, and we will support theget function. But the async is necessary to parallelize calls and allow async/await syntax. Remember to run the scripts withasyncio.run or it will fail with acoroutine 'main' was never awaited error.

We useasyncio.gather in the example below. It will wait for all the calls to finish, and the results are stored in aresponses array. The whole list of URLs will run, even if some fail. Then each response will have the status, request, response content, and other values as usual.

fromzenrowsimportZenRowsClientimportasyncioclient=ZenRowsClient("YOUR-API-KEY",concurrency=5,retries=1)asyncdefmain():urls= ["https://www.zenrows.com/",# ...    ]responses=awaitasyncio.gather(*[client.get_async(url)forurlinurls])forresponseinresponses:print(response.text)asyncio.run(main())

Contributing

Pull requests are welcome. For significant changes, please open an issue first to discuss what you would like to change.

License

MIT

About

SDK to access ZenRows API directly from Python. We handle proxies rotation, headless browsers and CAPTCHAs for you.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp