Skip to content
Simple user-agent middleware for Ruia
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ruia_ua
.gitignore
LICENSE
Pipfile
README.md
setup.py

README.md

ruia-ua

simple user-agent middleware for Ruia

Installation

pip install -U ruia-ua

Usage

ruia-ua will be automatically with a random User-Agent for your request's headers

from ruia import AttrField, TextField, Item, Spider
from ruia_ua import middleware


class HackerNewsItem(Item):
    target_item = TextField(css_select='tr.athing')
    title = TextField(css_select='a.storylink')
    url = AttrField(css_select='a.storylink', attr='href')


class HackerNewsSpider(Spider):
    start_urls = ['https://news.ycombinator.com/news?p=1', 'https://news.ycombinator.com/news?p=2']

    async def parse(self, response):
        # Do something...
        print(response.html)


if __name__ == '__main__':
    HackerNewsSpider.start(middleware=middleware)

Enjoy it :)

You can’t perform that action at this time.