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