Skip to main content

Official python client for the ScrapingAnt API.

Project description

ScrapingAnt API client for Python

PyPI version

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. Requires python 3.6+.

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 token

In order to get API token 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)

Main class of this library.

Param Type
token string

ScrapingAntClient.general_request

https://docs.scrapingant.com/request-response-format#available-parameters

Param Type Default
url string
cookies List[Cookie] None
js_snippet string None
proxy_type ProxyType datacenter
proxy_country str None
return_text boolean False
wait_for_selector str None
browser boolean True

IMPORTANT NOTE: js_snippet will be encoded to Base64 automatically by the ScrapingAnt client library.


Cookie

Class defining cookie. Currently it supports only name and value

Param Type
name string
value string

Response

Class defining response from API.

Param Type
content string
cookies List[Cookie]

Exceptions

ScrapingantClientException is base Exception class, used for all errors.

Exception Reason
ScrapingantInvalidTokenException The API token is wrong or you have exceeded the API calls request limit
ScrapingantInvalidInputException Invalid value provided. Please, look into error message for more info
ScrapingantInternalException Something went wrong with the server side code. Try again later or contact ScrapingAnt support
ScrapingantSiteNotReachableException The requested URL is not reachable. Please, check it locally
ScrapingantDetectedException The anti-bot detection system has detected the request. Please, retry or change the request settings.

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)

Useful links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapingant-client-0.3.7.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

scrapingant_client-0.3.7-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file scrapingant-client-0.3.7.tar.gz.

File metadata

  • Download URL: scrapingant-client-0.3.7.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for scrapingant-client-0.3.7.tar.gz
Algorithm Hash digest
SHA256 008307c782278bb1aab59b75e2bda83d20b4c642bf1fbba97c49960cd2c0b258
MD5 a13f81ba1ef75dcde07b74acd560c23c
BLAKE2b-256 00a474d2edff7f2d1dbdd8a39cb1086f6a6d06e19547f12143f4acd700e3e0ef

See more details on using hashes here.

File details

Details for the file scrapingant_client-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: scrapingant_client-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for scrapingant_client-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 67acf00419f381c6e324376c03b5acb25bc68d5d08270c400ab52ec4d7705e9b
MD5 423ba24bd653e6f1fe3386f215706e35
BLAKE2b-256 1151e100d3920ca24ff52694d4994067b8d7a47e8bd46509ce9993c196a6c7a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page