
github 地址: https://github.com/gaojiuli/gain/
gain 是为了让每大家能够轻松编写 python 爬虫, 它使用了 asyncio, uvloop 和 aiohttp.
pip install gain
Write spider.py:
from gain import Css, Item, Parser, Spider class Post(Item): title = Css('.entry-title') cOntent= Css('.entry-content') async def save(self): with open('scrapinghub.txt', 'a+') as f: f.writelines(self.results['title'] + '\n') class MySpider(Spider): start_url = 'https://blog.scrapinghub.com/' parsers = [Parser('https://blog.scrapinghub.com/page/\d+/'), Parser('https://blog.scrapinghub.com/\d{4}/\d{2}/\d{2}/[a-z0-9\-]+/', Post)] MySpider.run() run python spider.py

案例在 /example/ 目录下.
github 地址: https://github.com/gaojiuli/gain/
1 awolfly9 2017 年 6 月 2 日 via Android mark |
2 MIROKY 2017 年 6 月 2 日 via Android wow 马克 |
3 charove 2017 年 6 月 2 日 感觉好叼。。。 |
4 qs 2017 年 6 月 2 日 win 平台不支持 uvloop, 建议做个适配 |
6 maze1024 2017 年 6 月 3 日 aiohttp 的 http 解析配合 uvloop 不是很高效,建议看看 uvloop 的实现 https://github.com/MagicStack/httptools |
7 isaced 2017 年 6 月 3 日 建议把输出结果文件的操作封装一下用起来更舒服 |
8 PythonAnswer 2017 年 6 月 3 日 via Android uvloop win 跑不了啊 |
11 prasanta OP @PythonAnswer 看了楼上的意见,我准备暂时移除 uvloop |
12 chuanqirenwu 2017 年 6 月 3 日 不错,感谢作者的分享,已转发到 Pythonzhcn 社区,不知道是否允许? |
13 prasanta OP @chuanqirenwu 可以 |
14 pythonee 2017 年 6 月 3 日 mark |
15 hellogbk 2017 年 6 月 4 日 我这些天在用 pyquery 的时候是到一个问题,如果网页是以 <?xml version="1.0" encoding="UTF-8"?> 开头的则 pyquery 会出错。 不知道楼主有没有遇到。 |
17 hbmask 2017 年 6 月 4 日 mark 一下 |
18 hellogbk 2017 年 6 月 4 日 |
20 pb941129 2017 年 6 月 4 日 mark 一下 |