aioscrapy-0.2.0
توضیحات
Python asynchronous library for web scraping
| ویژگی | مقدار |
|---|---|
| سیستم عامل | Unix |
| نام فایل | aioscrapy-0.2.0 |
| نام | aioscrapy |
| نسخه کتابخانه | 0.2.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | eugen1j |
| ایمیل نویسنده | eugenij.bondar@gmail.com |
| آدرس صفحه اصلی | https://github.com/eugen1j/aioscrapy |
| آدرس اینترنتی | https://pypi.org/project/aioscrapy/ |
| مجوز | MIT |
# Python async library for web scraping
[](https://badge.fury.io/py/aioscrapy)
[](https://github.com/eugen1j/aioscrapy/blob/master/LICENSE)
[](https://travis-ci.com/github/eugen1j/aioscrapy)
[](https://codecov.io/gh/eugen1j/aioscrapy)
[](https://codebeat.co/projects/github-com-eugen1j-aioscrapy-master)
[](https://www.codacy.com/app/eugen1j/aioscrapy?utm_source=github.com&utm_medium=referral&utm_content=eugen1j/aioscrapy&utm_campaign=Badge_Grade)
## Installing
pip install aioscrapy
## Usage
Plain text scraping
```python
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
```python
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")
```
نیازمندی
| مقدار | نام |
|---|---|
| - | aiohttp |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7.0 | Python |
نحوه نصب
نصب پکیج whl aioscrapy-0.2.0:
pip install aioscrapy-0.2.0.whl
نصب پکیج tar.gz aioscrapy-0.2.0:
pip install aioscrapy-0.2.0.tar.gz