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

scrapy 批量写入,不足数量如何收尾

  •  
  •   360safe · Jul 4, 2017 · 3219 views
    This topic created in 3376 days ago, the information mentioned may be changed or developed.
    请问:
    我在 Pipelines 的__init__中设置了一个变量 AAA,代码里写着:
    if len(AAA)> 500:
    汇总写入一次数据;
    AAA= []

    请问:最后程序结束的时候,如果 AAA 不足 500,如何收尾。
    7 replies  •  2017-07-04 14:05:26 +08:00
    bazingaterry
        1
    bazingaterry  
       Jul 4, 2017 via iPhone
    结束的时候还有一个函数(一时之间想不起名字
    ldbC5uTBj11yaeh5
        2
    ldbC5uTBj11yaeh5  
       Jul 4, 2017
    判断一下当前时间,超过上次记录时间比如 1 分钟的话,即使不足 500 条也写入。算是最简单的 workaround 了。
    sikariba
        3
    sikariba  
       Jul 4, 2017
    就用一楼的那个,收尾的时候再写一次。closed 函数。
    https://docs.scrapy.org/en/latest/topics/spiders.html#scrapy.spiders.Spider.closed
    naomhan
        4
    naomhan  
       Jul 4, 2017   ❤️ 1
    pipline 里有个 close_spider 可以在这里导出
    1O
        5
    1O  
       Jul 4, 2017
    都是🐸,你看你都丑成啥样了。
    360safe
        6
    360safe  
    OP
       Jul 4, 2017
    谢谢大家,明白了,都怪自己没有细看官方文档。谢谢大家,学习成长了。
    360safe
        7
    360safe  
    OP
       Jul 4, 2017
    @1O 一样丑……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2430 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 08:46 · PVG 16:46 · LAX 01:46 · JFK 04:46
    ♥ Do have faith in what you're doing.