推荐学习书目
› 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
omg21
V2EX  ›  Python

BS4 不太稳定

  •  
  •   omg21 · Oct 6, 2016 · 3713 views
    This topic created in 3646 days ago, the information mentioned may be changed or developed.
    我用 BS4 取 text 的 parent 标签,有时候取到 text ,有时候取到 parent ,以前还以为是我把代码敲错了,后来才明白是 BS4 不稳定造成的。
    13 replies  •  2016-10-08 15:34:50 +08:00
    yangg
        1
    yangg  
       Oct 6, 2016 via iPhone
    Why not pyquery?
    omg21
        2
    omg21  
    OP
       Oct 6, 2016
    @yangg pyquery 相比 bs4 有哪些方面好用?
    julyclyde
        3
    julyclyde  
       Oct 6, 2016
    说实话,我不信
    omg21
        4
    omg21  
    OP
       Oct 6, 2016
    @julyclyde 我也不信,但是真让我遇到了,比方说我想在正则表达式里用变量,.find(text=re.compile(text1)),刚开始会报错,后来再试莫名又可以了
    pathletboy
        5
    pathletboy  
       Oct 6, 2016
    代码和目标内容贴出来看看?
    sherlocktheplant
        6
    sherlocktheplant  
       Oct 6, 2016
    应该是你用法有问题
    zmj1316
        7
    zmj1316  
       Oct 7, 2016
    真的假的?把代码和数据放上来重现一下?
    dsg001
        8
    dsg001  
       Oct 7, 2016
    https://github.com/scrapy/parsel , scrapy 的选择器,支持 re/css/xpath
    julyclyde
        9
    julyclyde  
       Oct 7, 2016
    @omg21 你能确定是相同输入么?同样输入重复多次、不同输入稳定顺序、不同输入乱序,你试试
    7sDream
        10
    7sDream  
       Oct 7, 2016
    说实话,我也不信。

    Show me the code~
    wyce2007
        11
    wyce2007  
       Oct 7, 2016
    部分网站会有类似 A/B 测试,可能楼主访问的过程中,获得了不同模板的页面
    Patrick95
        12
    Patrick95  
       Oct 8, 2016
    这种情况我觉得应该先怀疑是不是抓取的网站每次会返回不同的 HTML 结构。
    BS4 的选择器毕竟只是把 HTML 抽成树,怎么会不稳定呢?
    linruiyi
        13
    linruiyi  
       Oct 8, 2016
    说实话,我也不信。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   899 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 18:49 · PVG 02:49 · LAX 11:49 · JFK 14:49
    ♥ Do have faith in what you're doing.