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

scrapy 怎么设置爬虫跳到下一个 start_url?

  •  
  •   ningyu · Dec 18, 2015 · 4086 views
    This topic created in 3946 days ago, the information mentioned may be changed or developed.
    我现在是每个网站一个 start_url ,一个网站爬 1000(举个例子)个页面之后就跳到下一个网站进行爬取,
    宁雨 2015/12/18 18:04:40
    这种效果应该怎么实现?

    我试了一种方法,就是在爬取量达到 1000 个页面之后就把这个网站的域名从 allowed_domain 中去掉,这样的效果是爬虫依然从这个网站上爬取就是会把这个网站的 url 全部忽略,有没有有经验的同学指点一下
    3 replies  •  2015-12-19 10:13:32 +08:00
    fangdingjun
        1
    fangdingjun  
       Dec 18, 2015
    设定一个条件,当条件为 True 时
    yield scrapy.Request
    ningyu
        2
    ningyu  
    OP
       Dec 18, 2015
    @fangdingjun 能具体点吗,是在 parse_url 里面 yield ?
    fangdingjun
        3
    fangdingjun  
       Dec 19, 2015
    在 scrapy 的回调函数里停止返回 scrapy.Request 对象, scrapy 就会停止抓取
    你只需要在每次返回 scrapy.Request 时计数,在计数到达 1000 后停止返回 Request 即可
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   6030 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 02:19 · PVG 10:19 · LAX 19:19 · JFK 22:19
    ♥ Do have faith in what you're doing.