Skip to main content

Async-scrape

Perform webscrape asyncronously

Build Status

Async-scrape is a package which uses asyncio and aiohttp to scrape websites and has useful features built in.

Features

  • Breaks - pause scraping when a website blocks your requests consistently
  • Rate limit - slow down scraping to prevent being blocked

Installation

Async-scrape requires C++ Build tools v15+ to run.

pip install async-scrape

How to use it

Key inpur parameters:

  • post_process_func - the callable used to process the returned response
  • post_process_kwargs - and kwargs to be passed to the callable
  • use_proxy - should a proxy be used (if this is true then either provide a proxy or pac_url variable)
  • attempt_limit - how manay attempts should each request be given before it is marked as failed
  • rest_wait - how long should the programme pause between loops
  • call_rate_limit - limits the rate of requests (useful to stop getting blocked from websites)
  • randomise_headers - if set to True a new set of headers will be generated between each request

Get requests

# Create an instance
from async_scrape import AsyncScrape

def post_process(html, resp, **kwargs):
    """Function to process the gathered response from the request"""
    if resp.status == 200:
        return "Request worked"
    else:
        return "Request failed"

async_Scrape = AsyncScrape(
    post_process_func=post_process,
    post_process_kwargs={},
    fetch_error_handler=None,
    use_proxy=False,
    proxy=None,
    pac_url=None,
    acceptable_error_limit=100,
    attempt_limit=5,
    rest_between_attempts=True,
    rest_wait=60,
    call_rate_limit=None,
    randomise_headers=True
)

urls = [
    "https://www.google.com",
    "https://www.bing.com",
]

resps = async_Scrape.scrape_all(urls)

Post requests

# Create an instance
from async_scrape import AsyncScrape

def post_process(html, resp, **kwargs):
    """Function to process the gathered response from the request"""
    if resp.status == 200:
        return "Request worked"
    else:
        return "Request failed"

async_Scrape = AsyncScrape(
    post_process_func=post_process,
    post_process_kwargs={},
    fetch_error_handler=None,
    use_proxy=False,
    proxy=None,
    pac_url=None,
    acceptable_error_limit=100,
    attempt_limit=5,
    rest_between_attempts=True,
    rest_wait=60,
    call_rate_limit=None,
    randomise_headers=True
)

urls = [
    "https://eos1jv6curljagq.m.pipedream.net",
    "https://eos1jv6curljagq.m.pipedream.net",
]
payloads = [
    {"value": 0},
    {"value": 1}
]

resps = async_Scrape.scrape_all(urls, payloads=payloads)

Response

Response object is a list of dicts in the format:

{
    "url":url, # url of request
    "req":req, # combination of url and params
    "func_resp":func_resp, # response from post processing function
    "status":resp.status, # http status
    "error":None # any error encountered
}

License

MIT

Free Software, Hell Yeah!

Metadata

Release files for async-scrape 0.1.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-scrape 0.1.20
File Size Uploaded
async_scrape-0.1.20.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-scrape 0.1.20
File Interpreter ABI Platform
async_scrape-0.1.20-py3-none-any.whl Python 3 none any Details

Total release size: 29.5 kB

Release files / async_scrape-0.1.20.tar.gz

Download URL async_scrape-0.1.20.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f46a478983a7edc6e49259336366721dc1516266d692e66ff8d7c387d19e16c9
BLAKE2b-256 checksum
How to use checksums
4396b29c75a6b5d0367a232a71661191aa8a93d086355ceec4778f85c864b599
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.1

Release files / async_scrape-0.1.20-py3-none-any.whl

Download URL async_scrape-0.1.20-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36321206ce61656b0ee3d678b084d68b50040de4e04d8d34acc7b1d17271628c
BLAKE2b-256 checksum
How to use checksums
bbda3d93a7c1fd5211495dc05edc750d04e97bb8c21fc80a645fbb7f594825c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.1.20 This release

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

1 release file

0.1.7

2 release files

0.1.6

2 release files

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page