V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
zeal7s
V2EX  ›  Python

用了 scrapy 是否还需要用 beautifulsoup?

  •  
  •   zeal7s · 2015-03-10 07:30:49 +08:00 · 8499 次点击
    这是一个创建于 3334 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我作为新手刚学习scrapy,发现坑还挺多的。其中最主要的就是解析dom,我感觉用scrapy获取想要的元素特别麻烦特性counter-intuitive,没有beautifulsoup方便。但是感觉已经用了scrapy再在代码中import beautifulsoup很不优雅。不晓得各位有没有类似的问题?

    用requests+beautifulsoup已经能够解决问题了,为什么还需要用scrapy呢?
    16 条回复    2015-03-11 12:33:10 +08:00
    simapple
        1
    simapple  
       2015-03-10 08:29:59 +08:00
    简单的做urllib+re就可以,scrapy是一套框架,如果是工程项目,要考虑的深度 广度 并发控制 作业调度 等等
    limbo0
        2
    limbo0  
       2015-03-10 08:44:46 +08:00
    感觉xpath特别方便,是lz没找对方法把
    raptor
        3
    raptor  
       2015-03-10 08:51:45 +08:00
    如果你的需求用requests+beautifulsoup就可以解决,那就这样做好了,最多加上gevent。

    scrapy的强大在于配套功能非常多
    crazycookie
        4
    crazycookie  
       2015-03-10 10:58:46 +08:00
    为啥不用xpath?
    professorz
        5
    professorz  
       2015-03-10 14:07:29 +08:00
    @simapple 能说说这些名词的具体实现吗?

    @raptor 能讲讲scrapy都有啥好用的配套功能吗?
    谢谢
    yetone
        6
    yetone  
       2015-03-10 14:42:52 +08:00
    pyquery 秒一切
    crazyxin1988
        7
    crazyxin1988  
       2015-03-10 14:44:41 +08:00
    赶脚requests+beautifulsoup 就蛮好的
    fumer
        8
    fumer  
       2015-03-10 16:05:13 +08:00
    不需要用beautifulsoup
    rhythmer
        9
    rhythmer  
       2015-03-10 18:17:56 +08:00
    @limbo0 感觉xpath对于标准的html网页的处理还可以,但对于很奇怪的html网页我还不知道怎么抓取数据。最近打算从花瓣去抓图片,huaban.com/favorite/home,用scrapy的xpath就觉得很麻烦
    limbo0
        10
    limbo0  
       2015-03-10 18:52:30 +08:00   ❤️ 1
    @rhythmer 图片的地址是javascript生成的xpath根本抓不了,正则或许是个好的选择
    latteczy
        11
    latteczy  
       2015-03-10 20:36:10 +08:00   ❤️ 1
    @rhythmer 抓图片用ImagePipeline,把src的值抓下来,转到这个地址上应该就可以了吧
    zeal7s
        12
    zeal7s  
    OP
       2015-03-11 06:22:57 +08:00 via iPad
    @limbo0 确实没有学过xpath
    zeal7s
        13
    zeal7s  
    OP
       2015-03-11 06:24:48 +08:00 via iPad   ❤️ 1
    @rhythmer 同感,xpath从功能和易用性上来说肯定不如beautifulsoup
    raptor
        14
    raptor  
       2015-03-11 10:42:52 +08:00
    @professorz 官方文档说了很多啊,举例而言就有:它自带一个WEB管理界面,支持TELNET登录管理,有交互式SHELL可以调试对抓取内容的解析,内置多种中间件可处理SESSION,COOKIE,HTTP压缩,身份验证……
    raptor
        15
    raptor  
       2015-03-11 10:44:35 +08:00
    顺便问一句,beatifulsoup真有这么好?我怎么觉得还是pyquery用起来更简单。
    kingname
        16
    kingname  
       2015-03-11 12:33:10 +08:00
    xpath秒杀bs4,beaitifulsoup4还是感觉不好用。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   994 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:05 · PVG 04:05 · LAX 13:05 · JFK 16:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.