Python async library for web scraping
Installing
pip install aioscrapy
Usage
Plain text scraping
import asyncio
import json
from aioscrapy import Client, WebTextClient, SingleSessionPool, Dispatcher, SimpleWorker
class CustomClient(Client[str, dict]):
def __init__(self, client: WebTextClient):
self._client = client
async def fetch(self, key: str) -> dict:
data = await self._client.fetch(key)
return json.loads(data)
async def main():
pool = SingleSessionPool()
dispatcher = Dispatcher(['https://httpbin.org/get'])
client = CustomClient(WebTextClient(pool))
worker = SimpleWorker(dispatcher, client)
result = await worker.run()
return result
loop = asyncio.get_event_loop()
print(loop.run_until_complete(main()))
Byte content downloading
import asyncio
from aioscrapy import Client, WebByteClient, SingleSessionPool, Dispatcher, SimpleWorker
class CustomClient(Client[str, bytes]):
def __init__(self, client: WebByteClient):
self._client = client
async def fetch(self, key: str) -> bytes:
data = await self._client.fetch(key)
return data
async def main():
pool = SingleSessionPool()
dispatcher = Dispatcher(['https://httpbin.org/image'])
client = CustomClient(WebByteClient(pool))
worker = SimpleWorker(dispatcher, client)
result = await worker.run()
return result
loop = asyncio.get_event_loop()
data: dict = loop.run_until_complete(main())
for url, byte_content in data.items():
print(url + ": " + str(len(byte_content)) + " bytes")
Metadata
Release files for aioscrapy 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aioscrapy-0.2.0.tar.gz | 6.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aioscrapy-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.2 kB
Release files / aioscrapy-0.2.0.tar.gz
| Download URL | aioscrapy-0.2.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65bafc1c46d3f904bd314a68ae6d256b838c37caaae9cdaf69aa18145f15fd02
|
|
BLAKE2b-256 checksum How to use checksums |
718a7bbc2dae9f52946b643157479731415000525bcfeab646e5a42467433f33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.9
|
Release files / aioscrapy-0.2.0-py3-none-any.whl
| Download URL | aioscrapy-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b33ba670a340b431cff742035bd9cc6cc5be46d99b4c5c934f12690e67b8e618
|
|
BLAKE2b-256 checksum How to use checksums |
c513541b29f6d7b05540d72cd433f9cbc0e73b31a370bb525141e5b1cdbccd71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.9
|