requests 的作者的新项目 requests-html

2018 年 2 月 28 日
 yangzhezjgs
https://github.com/kennethreitz/requests-html

This library intends to make parsing HTML (e.g. scraping the web) as simple and intuitive as possible.

When using this library you automatically get:

-Full JavaScript support!
-CSS Selectors (a.k.a jQuery-style, thanks to PyQuery).
-XPath Selectors, for the faint at heart.
-Mocked user-agent (like a real web browser).
-Automatic following of redirects.
-Connection – pooling and cookie persistence.
-The Requests experience you know and love, with magical parsing abilities.

对 requests 做了封装,添加了解析 html 的接口,总代码现在是 399 行,还在更新
12580 次点击
所在节点    Python
44 条回复
zhoulv2012
2018 年 2 月 28 日
都是实用的功能啊!
knightdf
2018 年 2 月 28 日
还可以解析 JS ?怎么感觉是个爬虫库了
dqh3000
2018 年 2 月 28 日
哎呀呀呀呀?

不错不错……这个好
ioven
2018 年 2 月 28 日
https://github.com/scrapy/parsel 一直用的这货,re css xpath 用起来很爽
Mavious
2018 年 2 月 28 日
非程序猿表示非常感兴趣。requests 太好用了,太是适合我等毫无基础的小白了,轻松上手。
sowish
2018 年 2 月 28 日
看了下,安装 requests-html 同时需要 bs4,lxml 等库,估计还是依赖于这些库
4BVL25L90W260T9U
2018 年 2 月 28 日
恕我直言,没看懂这个库存在的意义,lxml 足够好用了,重点是 xpath 这种东西应该存在配置里,而不是把解析逻辑写在代码里
wfd0807
2018 年 2 月 28 日
Full JavaScript Support by Chromium headless mode.
wfd0807
2018 年 2 月 28 日
the first time you ever run the render() method, it will download Chromium ...
yech1990
2018 年 2 月 28 日
399 行代码已经 4600 stars 了。

---

另外作者现在摄影技术也逆天。
yech1990
2018 年 2 月 28 日
看依赖需要 bs4
但代码中又没有出现?
yangzhezjgs
2018 年 2 月 28 日
@yech1990 这个应该是之前用了 bs4,后来又改用其他的,但是依赖里面没有去掉,因为昨天我看的时候代码才 200 行
wellsc
2018 年 2 月 28 日
像是拯救世界
tcpdump
2018 年 2 月 28 日
文档好多错误,跑不起来
VicYu
2018 年 2 月 28 日
for the horde
abmin521
2018 年 2 月 28 日
顶 k 神下
Ginson
2018 年 2 月 28 日
研究中。文档确实错误挺多
Tutorial 第一行代码 from requests_html import HTMLSession 就报错,应该 import Session
LINAICAI
2018 年 2 月 28 日
明显是爬虫嘛……
WildCat
2018 年 2 月 28 日
感谢作者,正需求这样的库!



@Ginson
import HTMLSession 报错的原因是因为它会自动加载 fake_useragents.json,你的网络可能不能访问 cloudfront。
认真读一秒报错提示吧。
Ginson
2018 年 2 月 28 日
@WildCat 谢谢,我还在研究。不过报错提示我实在没看出啥…

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://v2ex.ih06.com/t/433435

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX