Official python client for the ScrapingAnt API.
Project description
ScrapingAnt API client for Python
scrapingant-client
is the official library to access ScrapingAnt API from your
Python applications. It provides useful features like parameters encoding to improve the ScrapingAnt usage experience.
Quick Start
from scrapingant_client import ScrapingAntClient
client = ScrapingAntClient(token='<YOUR-SCRAPINGANT-API-TOKEN>')
# Scrape the example.com site.
result = client.general_request('https://example.com')
print(result.content)
API key
In order to get API key you'll need to register at ScrapingAnt Service
API Reference
All public classes, methods and their parameters can be inspected in this API reference.
ScrapingAntClient(token)
Param | Type | Default |
---|---|---|
token | string |
ScrapingAntClient.general_request(url, cookies, js_snippet, proxy_country, return_text)
⇒ Response
https://docs.scrapingant.com/request-response-format#available-parameters
Param | Type | Default |
---|---|---|
url | string |
|
cookies | List[Cookie] |
None |
js_snippet | string |
None |
proxy_country | ProxyCountry |
None |
return_text | boolean |
False |
IMPORTANT NOTE: js_snippet
will be encoded to Base64 automatically by the ScrapingAnt client library.
Cookie
Class defining cookie. Curently supports only name and value
Param | Type |
---|---|
name | string |
value | string |
ProxyCountry
Enum containing all available proxy countries
Response
Class defining cookie. Curently supports only name and value
Param | Type |
---|---|
content | string |
cookies | List[Cookie] |
ScrapingantClientException
ScrapingantClientException
is base Exception class, used for all errors.
Examples
Sending custom cookies
from scrapingant_client import ScrapingAntClient
from scrapingant_client import Cookie
client = ScrapingAntClient(token='<YOUR-SCRAPINGANT-API-TOKEN>')
result = client.general_request(
'https://httpbin.org/cookies',
cookies=[
Cookie(name='cookieName1', value='cookieVal1'),
Cookie(name='cookieName2', value='cookieVal2'),
]
)
print(result.content)
# Response cookies is a list of Cookie objects
# They can be used in next requests
response_cookies = result.cookies
Executing custom JS snippet
from scrapingant_client import ScrapingAntClient
client = ScrapingAntClient(token='<YOUR-SCRAPINGANT-API-TOKEN>')
customJsSnippet = """
var str = 'Hello, world!';
var htmlElement = document.getElementsByTagName('html')[0];
htmlElement.innerHTML = str;
"""
result = client.general_request(
'https://example.com',
js_snippet=customJsSnippet,
)
print(result.content)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for scrapingant_client-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fdf7d21c5dd77cd81bf42e8670acc7924ea94bc865176789b5de8fbdc658fcd |
|
MD5 | ffe711ac9226dc3b1ac7ecc56a5e9662 |
|
BLAKE2b-256 | 32af2ddf471df8bfd766fe86e855e87a3d2b519a54afb969b150001e7d67425d |