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

Python : 爬取所有 ip 数据并存入 mongodb,支持中断恢复执行

  •  
  •   xiaojieluoff · May 27, 2017 · 2054 views
    This topic created in 3414 days ago, the information mentioned may be changed or developed.

    数据采集自 ip-api.com

    在 celery 队列中获取数据并存入 mongodb 数据库

    支持程序中断后从上次停下的地方继续采集

    支持 python3+

    Github 地址: https://github.com/xiaojieluo/ip-database

    下面截图是我在本地电脑爬的,开了 4 个 worker,celery 很容易横向拓展,如果多加几台服务器,做成分布式爬虫,速度应该还是可以的

    截图

    安装

    $ pip install -r requirements.txt
    

    使用

    1. 配置 mongodb 连接信息

    ip-database 会将采集的数据存储到 mongodb 中,所以需要在 db.py 中配置 mongodb 的连接信息

    2. 启动 redis-server 和 celery

    celery 使用 redis 存储任务队列,需要启动 redis-server

    
    $ redis-server
    
    $ celery -A task worker --loglevel=info
    

    3. 启动主程序

    
    $ python ip.py
    
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2382 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 01:50 · PVG 09:50 · LAX 18:50 · JFK 21:50
    ♥ Do have faith in what you're doing.