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

使用 beautifulsoup 解析网页非常的慢,有什么同类产品可以替代么?

  •  
  •   halfcrazy ·
    halfcrazy · Apr 28, 2014 · 16560 views
    This topic created in 4574 days ago, the information mentioned may be changed or developed.
    另 如果单纯用正则匹配的话,效率如何?
    26 replies  •  2014-05-06 16:11:27 +08:00
    for4
    for4
    Apr 28, 2014
    1
    halfcrazy
    halfcrazy
    OP
    Apr 28, 2014
    2
    @for4 如果性能能相差十倍,确实很诱人,这就试试去
    qonco
    qonco
    Apr 28, 2014
    3
    jsoup
    qonco
    qonco
    Apr 28, 2014
    4
    正则不是用来匹配html的
    Ever
    Ever
    Apr 28, 2014
    5
    @halfcrazy 美丽汤指定第二个参数为lxml就能走lxml parser, 不用重写。
    halfcrazy
    halfcrazy
    OP
    Apr 28, 2014
    6
    @qonco jsoup是java的啊,另我的意思是只用正则来解析网页提取内容。
    halfcrazy
    halfcrazy
    OP
    Apr 28, 2014
    7
    @Ever 是这样么? soup = BeautifulSoup(page,"lxml")
    halfcrazy
    halfcrazy
    OP
    Apr 28, 2014
    8
    @Ever 用了这个lxml’s HTML parser效果似乎不是很明显啊
    bilipan
    bilipan
    Apr 28, 2014
    9
    pyquery可以试下,语法跟jquery类似
    binux
    binux
    Apr 28, 2014
    10
    正则比xml建树快得多,直接用xpath,比soup,pyquery快。
    即便如此,lxml单进程每秒30个页面还是没问题的。加大并发就好了。
    flyer103
    flyer103
    Apr 28, 2014 via Android
    11
    @binux 想问下 “lxml单进程每秒30个页面还是没问题的” 是如何测出来的,平均获取单个页面中的数据条目有多少?
    binux
    binux
    Apr 28, 2014
    12
    @flyer103 timeit,每个页面80条xpath规则
    andyhu
    andyhu
    Apr 28, 2014
    13
    可以不用python吗?nodejs+cheerio非常爽,完全jquery的语法解析,速度也很快
    kxxoling
    kxxoling
    Apr 28, 2014 via iPad
    14
    bs有坑啊!lxml!
    187j3x1
    187j3x1
    Apr 28, 2014
    15
    匹配一堆相同内容 正则舒服很多 能正则就正则
    dreasky
    dreasky
    Apr 28, 2014
    16
    亲测正则的速度快最灵活
    a2z
    a2z
    Apr 28, 2014
    17
    bs4
    tomnee
    tomnee
    Apr 28, 2014
    18
    pyquery, 套的lxml, 性能比bs好,用起来比较简单。
    daiv
    daiv
    Apr 28, 2014
    19
    pyquery,用起来还是很舒服的
    walleL
    walleL
    Apr 28, 2014❤️2
    20


    不知道大家有没有注意过这个功能, 很赞啊
    okidogi
    okidogi
    Apr 28, 2014
    21
    beautifulsoup4 使用的就是lxml的库,应该会快一些。

    pip install beautifulsoup4
    halfcrazy
    halfcrazy
    OP
    Apr 28, 2014
    22
    @okidogi 默认用的是html.parser吧 ,lxml好像要手动指定
    chevalier
    chevalier
    Apr 29, 2014
    23
    @walleL 一直在用,写爬虫XPath解析网页必备
    orancho
    orancho
    Apr 29, 2014 via Android
    24
    nokigiri
    Ever
    Ever
    Apr 29, 2014
    25
    @halfcrazy 是不是单个文档过大? 数量大试试开线程池解决, lxml会释放GIL, 能有效利用多核。
    remnet
    remnet
    May 6, 2014
    26
    beautifulsoup 用过 感觉的确挺慢的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2681 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 13:14 · PVG 21:14 · LAX 05:14 · JFK 08:14
    ♥ Do have faith in what you're doing.