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