推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yangzhezjgs
V2EX  ›  Python

requests 的作者的新项目 requests-html

  •  1
     
  •   yangzhezjgs · Feb 28, 2018 · 12253 views
    This topic created in 3020 days ago, the information mentioned may be changed or developed.
    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 行,还在更新
    Supplement 1  ·  Feb 28, 2018
    目前版本还不稳定,作者应该还在修改更新中,出现问题请稍安勿躁
    现在代码新增为 484 行(昨天我刚看到的时候是 200 多行)
    44 replies    2018-05-27 21:31:45 +08:00
    mYYnSmiTEQWcCwAr
        1
    mYYnSmiTEQWcCwAr  
       Feb 28, 2018 via Android
    mark 先 star 为敬
    lhx2008
        2
    lhx2008  
       Feb 28, 2018 via Android
    把 pyquery 和 xpath 弄进来了,还有自动 useragent,是要一统江湖的节奏
    co3site
        3
    co3site  
       Feb 28, 2018 via Android
    观望中,先 star
    Sanko
        4
    Sanko  
       Feb 28, 2018 via Android
    orz
    prolic
        5
    prolic  
       Feb 28, 2018
    star 为敬,beautifulsoup 用着还是不够爽
    weiwio
        6
    weiwio  
       Feb 28, 2018 via Android
    今天看了一下,原来是新项目,很有希望啊
    fyyz
        7
    fyyz  
       Feb 28, 2018
    吊炸天
    tuding
        8
    tuding  
       Feb 28, 2018
    这个作者好腻害,好多牛逼项目
    steveway
        9
    steveway  
       Feb 28, 2018 via Android
    看作者就 star 系列
    lfzyx
        10
    lfzyx  
       Feb 28, 2018
    可以放弃 bs4 了?
    CSM
        11
    CSM  
       Feb 28, 2018
    期待有人封装 aiohttp
    sunwei0325
        12
    sunwei0325  
       Feb 28, 2018
    如果下载和解析分开异步进行就好了
    angelshq
        13
    angelshq  
       Feb 28, 2018
    mark
    Zzde
        14
    Zzde  
       Feb 28, 2018 via iPhone
    Mark
    find456789
        15
    find456789  
       Feb 28, 2018
    不太明白,这个 库 用来替代谁的?
    find456789
        16
    find456789  
       Feb 28, 2018
    请问这个库 是 requests+bs4 吗
    douglarek
        17
    douglarek  
       Feb 28, 2018   ❤️ 1
    xxx for humans 又来了?没有 xxx 之前莫不是大家都在吃猪食 ?
    soulmine
        18
    soulmine  
       Feb 28, 2018
    @find456789 大约看了下 大概类似于 requests+bs4+selenium/phantomjs 不过后面两个现在只是封装了一小部分功能 比如通过 css selector 解析或者执行 js 代码这种
    soulmine
        19
    soulmine  
       Feb 28, 2018
    @sunwei0325 你可以自己异步啊 比如用队列什么的
    hugo2lee
        20
    hugo2lee  
       Feb 28, 2018
    Only later versions of Python 3 are supported. 好评
    zhoulv2012
        21
    zhoulv2012  
       Feb 28, 2018
    都是实用的功能啊!
    knightdf
        22
    knightdf  
       Feb 28, 2018
    还可以解析 JS ?怎么感觉是个爬虫库了
    dqh3000
        23
    dqh3000  
       Feb 28, 2018
    哎呀呀呀呀?

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

    ---

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



    @Ginson
    import HTMLSession 报错的原因是因为它会自动加载 fake_useragents.json,你的网络可能不能访问 cloudfront。
    认真读一秒报错提示吧。
    Ginson
        40
    Ginson  
       Feb 28, 2018
    @WildCat 谢谢,我还在研究。不过报错提示我实在没看出啥…
    WildCat
        41
    WildCat  
       Feb 28, 2018
    @Ginson 你这个应该也是同样的问题我觉得。。。
    换 jupyter lab/notebook 吧,命令行 IPython 还是有点不好用。
    jimmyye
        42
    jimmyye  
       Feb 28, 2018
    版本更新太快,所以用的时候要注意安装的版本和 Github 上的代码 commit 时间。
    pdog18
        43
    pdog18  
       Apr 16, 2018
    我想问下这个库可以将<script>标签里面的 js 代码快速转换成 python 对象吗?有什么办法吗?正好遇到这个问题。
    现在只能换成字符串强行切
    windcode
        44
    windcode  
       May 27, 2018
    目前已经 700 行代码,7700+ star,有没有人用过,感觉如何?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   853 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 110ms · UTC 21:28 · PVG 05:28 · LAX 14:28 · JFK 17:28
    ♥ Do have faith in what you're doing.