Skip to main content

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

doc

Ready

please submit your sugguestion to owner by issue

Thanks

aiohttp

scrapy

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

aio-scrapy-1.2.1.tar.gz (88.5 kB view details)

Uploaded Source

Built Distribution

aio_scrapy-1.2.1-py3-none-any.whl (124.6 kB view details)

Uploaded Python 3

File details

Details for the file aio-scrapy-1.2.1.tar.gz.

File metadata

  • Download URL: aio-scrapy-1.2.1.tar.gz
  • Upload date:
  • Size: 88.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.7

File hashes

Hashes for aio-scrapy-1.2.1.tar.gz
Algorithm Hash digest
SHA256 e9d2aad0de2e10d37f9e85c32d2a42de583e46ffba960cba1eb31377b4480aab
MD5 51a201c8c758d7d275b988c4ab3b493d
BLAKE2b-256 2311321d6bd95a2fd48a5d5b8bc176ca641faa09b127f7f74b485a0ff5d0f513

See more details on using hashes here.

File details

Details for the file aio_scrapy-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: aio_scrapy-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 124.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.7

File hashes

Hashes for aio_scrapy-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c4bef93a07edf31ea92aea10fd7cfaca7bcdf58c71581361d2695d01576c3ed
MD5 605fdf650e06f0e092fb95d2ee5fd09b
BLAKE2b-256 5304c12b94542d27c8f7ebd570da0b6c0f2dd077c541317453003aeb24381e1f

See more details on using hashes here.

Supported by

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