基于py3异步的web抓取框架
crawler的Python项目详细描述
基于py3异步aiohttp库的web抓取框架。
用法示例
importrefromitertoolsimportislicefromcrawlerimportCrawler,RequestRE_TITLE=re.compile(r'<title>([^<]+)</title>',re.S|re.I)classTestCrawler(Crawler):deftask_generator(self):forhostinislice(open('var/domains.txt'),100):host=host.strip()ifhost:yieldRequest('http://%s/'%host,tag='page')defhandler_page(self,req,res):print('Result of request to {}'.format(req.url))try:title=RE_TITLE.search(res.body).group(1)exceptAttributeError:title='N/A'print('Title: {}'.format(title))bot=TestCrawler(concurrency=10)bot.run()
安装
pip install crawler
依赖关系
- python=3.4
- aiohttp