A high-level Web Crawling and Web Scraping framework based on Asyncio
Project description
aio-scrapy
An asyncio + aiolibs crawler imitate scrapy framework
English | 中文
Overview
- aio-scrapy framework is base on opensource project Scrapy & scrapy_redis.
- aio-scrapy implements compatibility with scrapyd.
- aio-scrapy implements redis queue and rabbitmq queue.
- aio-scrapy is a fast high-level web crawling and web scraping framework, used to crawl websites and extract structured data from their pages.
- Distributed crawling/scraping.
Requirements
- Python 3.7+
- Works on Linux, Windows, macOS, BSD
Install
The quick way:
pip install aio-scrapy -U
Usage
create project spider:
aioscrapy startproject project_quotes
cd project_quotes
aioscrapy genspider quotes
quotes.py
from aioscrapy.spiders import Spider
class QuotesMemorySpider(Spider):
name = 'QuotesMemorySpider'
start_urls = ['https://quotes.toscrape.com']
async def parse(self, response):
for quote in response.css('div.quote'):
yield {
'author': quote.xpath('span/small/text()').get(),
'text': quote.css('span.text::text').get(),
}
next_page = response.css('li.next a::attr("href")').get()
if next_page is not None:
yield response.follow(next_page, self.parse)
if __name__ == '__main__':
QuotesMemorySpider.start()
run the spider:
aioscrapy crawl quotes
create single script spider:
aioscrapy genspider single_quotes -t single
single_quotes.py:
from aioscrapy.spiders import Spider
class QuotesMemorySpider(Spider):
name = 'QuotesMemorySpider'
custom_settings = {
"USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
# 'DOWNLOAD_DELAY': 3,
# 'RANDOMIZE_DOWNLOAD_DELAY': True,
# 'CONCURRENT_REQUESTS': 1,
# 'LOG_LEVEL': 'INFO'
}
start_urls = ['https://quotes.toscrape.com']
@staticmethod
async def process_request(request, spider):
""" request middleware """
return request
@staticmethod
async def process_response(request, response, spider):
""" response middleware """
return response
@staticmethod
async def process_exception(request, exception, spider):
""" exception middleware """
pass
async def parse(self, response):
for quote in response.css('div.quote'):
yield {
'author': quote.xpath('span/small/text()').get(),
'text': quote.css('span.text::text').get(),
}
next_page = response.css('li.next a::attr("href")').get()
if next_page is not None:
yield response.follow(next_page, self.parse)
async def process_item(self, item):
print(item)
if __name__ == '__main__':
QuotesMemorySpider.start()
run the spider:
aioscrapy runspider quotes.py
more commands:
aioscrapy -h
Documentation
Ready
please submit your sugguestion to owner by issue
Thanks
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
aio-scrapy-1.0.2.tar.gz
(87.2 kB
view details)
Built Distribution
aio_scrapy-1.0.2-py3-none-any.whl
(123.0 kB
view details)
File details
Details for the file aio-scrapy-1.0.2.tar.gz
.
File metadata
- Download URL: aio-scrapy-1.0.2.tar.gz
- Upload date:
- Size: 87.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.28.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b44f456e5afdb3104876c3e81a506cae560d37859be62134b44e6423198a33a |
|
MD5 | 0d83273ea71ea1ff2e10ac164cb80d50 |
|
BLAKE2b-256 | d70e2358e473673c0ede5b7a63663a1c81283b685fc76a63d41a59da0c704480 |
File details
Details for the file aio_scrapy-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: aio_scrapy-1.0.2-py3-none-any.whl
- Upload date:
- Size: 123.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.28.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8f89ea79ffb6feda06fa98db9547455f7cc021e15085ac3b476416da14c998a |
|
MD5 | fb74cbe57f9c64971cedf21be02935a6 |
|
BLAKE2b-256 | 899bb7b68c2cea1638bd986abccdfaefda924e51d71742f40030e734129a21cb |