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

请教使用 scrapy 爬取豆瓣读书的时候,无法多页面爬取的解决办法

  •  
  •   anguslg · Mar 8, 2017 · 2894 views
    This topic created in 3553 days ago, the information mentioned may be changed or developed.
    初学 Python ,在用 scrapy 来爬取豆瓣读书练习。目前爬取单页面的书籍没有问题

    在用 scrapy 提供的 Rule 和 LinkExtractor 模块练习爬取多页面的时候,始终无法获取的到下一页的结果,折腾一天无解
    爬虫主要代码在下面,请各位给看看问题所在,感谢!

    9 replies  •  2017-03-09 00:34:26 +08:00
    bazingaterry
    bazingaterry
    Mar 8, 2017
    1
    return book --> yield book
    freestyle
    freestyle
    Mar 8, 2017
    2
    LinkExtractor 的正则写错了 r'/tag/小说\?start=\d+'
    freestyle
    freestyle
    Mar 8, 2017
    3
    @bazingaterry return 也可以
    freestyle
    freestyle
    Mar 8, 2017❤️1
    4
    不知道你这是不是 Python2 可能要加 u ur'/tag/小说\?start=\d+'
    congminghaoxue92
    congminghaoxue92
    Mar 8, 2017
    5
    你没有加翻页功能吧,加上翻页判断。
    anguslg
    anguslg
    OP
    Mar 8, 2017
    6
    @freestyle 使用的 Python3 ,正则表达式我测试过,可正确检测到对应的链接文本
    anguslg
    anguslg
    OP
    Mar 8, 2017
    7
    @congminghaoxue92 scrapy 框架已经帮做了这个事情
    nicevar
    nicevar
    Mar 9, 2017❤️1
    8
    问题出在 rules 上, callback 随便重新写个函数,不用覆盖 parse 就行了
    anguslg
    anguslg
    OP
    Mar 9, 2017
    9
    @nicevar 确实是这个问题。很奇怪,我在开始使用 Rule 来爬取多页的时候,就把 callback 函数重写了,但是当时也是只能只能爬取单个页面……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1826 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:15 · PVG 08:15 · LAX 16:15 · JFK 19:15
    ♥ Do have faith in what you're doing.