Coder Social home page Coder Social logo

frankiegu / python3-concurrency-pics-02 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wangy8961/python3-concurrency-pics-02

0.0 0.0 0.0 116 KB

爬取 www.mzitu.com 全站图片,截至目前共5162个图集,16.5万多张美女图片,使用 asyncio 和 aiohttp 实现的异步版本只需要不到2小时就能爬取完成。按日期创建图集目录,保存更合理。控制台只显示下载的进度条,详细信息保存在日志文件中。支持异常处理,不会终止爬虫程序。失败的请求,下次再执行爬虫程序时会自动下载

Home Page: http://www.madmalls.com/blog/post/python3-concurrency-pics-02/

Python 100.00%

python3-concurrency-pics-02's Introduction

Python aiohttp BeautifulSoup4 requests pymongo progressbar2

1. 进度条

2. 部分截图

分析爬取的过程:

3. 爬虫系列

4. 使用方法

此代码库中只有低速同步下载版本,协程高速版本请访问: https://madmalls.com/blog/post/python3-concurrency-pics-02/

4.1 下载代码

[root@CentOS ~]# git clone https://github.com/wangy8961/python3-concurrency-pics-02.git
[root@CentOS ~]# cd python3-concurrency-pics-02/

4.2 准备虚拟环境

如果你的操作系统是Linux:

[root@CentOS python3-concurrency-pics-02]# python3 -m venv venv3
[root@CentOS python3-concurrency-pics-02]# source venv3/bin/activate

Windows激活虚拟环境的命令是: venv3\Scripts\activate

4.3 安装依赖包

如果你的操作系统是Linux:

(venv3) [root@CentOS python3-concurrency-pics-02]# pip install -r requirements-linux.txt

如果你的操作系统是Windows(不会使用uvloop):

(venv3) C:\Users\wangy> pip install -r requirements-win32.txt

4.4 测试

由于图片有16万多张,所以测试的时候,你可以指定只下载100个图集来对比同步下载多线程下载异步下载的效率区别,修改以下三个脚本中的TEST_NUM = 100

建议每次测试完,都删除相关目录:

(venv3) [root@CentOS python3-concurrency-pics-02]# rm -rf downloads/ logs/ __pycache__/

删除数据库记录:

(venv3) [root@CentOS python3-concurrency-pics-02]# mongo
MongoDB shell version v3.6.6
connecting to: mongodb://127.0.0.1:27017
...
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
mzitu   0.036GB
> use mzitu
switched to db mzitu
> db.dropDatabase()
{ "dropped" : "mzitu", "ok" : 1 }
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
> 

(1) 依序下载

(venv3) [root@CentOS python3-concurrency-pics-02]# python sequential.py

(2) 多线程下载

(venv3) [root@CentOS python3-concurrency-pics-02]# python threadpool.py

(3) 异步下载

(venv3) [root@CentOS python3-concurrency-pics-02]# python asynchronous.py

python3-concurrency-pics-02's People

Contributors

wangy8961 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.