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
ningyu
V2EX  ›  Python

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

  •  
  •   ningyu · 2015-12-18 18:16:40 +08:00 · 2852 次点击
    这是一个创建于 3051 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我现在是每个网站一个 start_url ,一个网站爬 1000(举个例子)个页面之后就跳到下一个网站进行爬取,
    宁雨 2015/12/18 18:04:40
    这种效果应该怎么实现?

    我试了一种方法,就是在爬取量达到 1000 个页面之后就把这个网站的域名从 allowed_domain 中去掉,这样的效果是爬虫依然从这个网站上爬取就是会把这个网站的 url 全部忽略,有没有有经验的同学指点一下
    3 条回复    2015-12-19 10:13:32 +08:00
    fangdingjun
        1
    fangdingjun  
       2015-12-18 18:26:53 +08:00
    设定一个条件,当条件为 True 时
    yield scrapy.Request
    ningyu
        2
    ningyu  
    OP
       2015-12-18 18:31:05 +08:00
    @fangdingjun 能具体点吗,是在 parse_url 里面 yield ?
    fangdingjun
        3
    fangdingjun  
       2015-12-19 10:13:32 +08:00
    在 scrapy 的回调函数里停止返回 scrapy.Request 对象, scrapy 就会停止抓取
    你只需要在每次返回 scrapy.Request 时计数,在计数到达 1000 后停止返回 Request 即可
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4062 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:24 · PVG 13:24 · LAX 22:24 · JFK 01:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.