Python 3 爬虫|第10章:爬取少量妹子图

  • 原创
  • Madman
  • /
  • /
  • 0
  • 10652 次阅读

Python 3 爬虫-min.png

Synopsis: https://gank.io/api 提供了 API 来获取分享的图片,请求该 API 后将返回 JSON 数据,API 具体用法请自行查看该网址,截至目前共分享了 656 张图片

代码已上传到 https://github.com/wangy8961/python3-concurrency-pics-01 ,欢迎 star

1. 准备环境

1.1 安装 CentOS

建议使用 VMware 安装一台 CentOS-7.3 虚拟机,参考 http://www.madmalls.com/blog/post/customize-centos-7-3-autoinstall-iso/

1.2 安装 Python3

参考 http://www.madmalls.com/blog/post/deploy-flask-gunicorn-nginx-supervisor-on-centos7/#3-python3

1.3 安装依赖的包

# pip install -r requirements-linux.txt

如果你使用 Windows,不会使用 uvloop:

# pip install -r requirements-win32.txt

1.4 安装 Git

# yum -y install git

克隆代码,已上传到 Github

# git clone git@github.com:wangy8961/python3-concurrency-pics-01.git

2. 测试

2.1 依序下载

使用 requests 模块来获取 HTTP 响应,由于部分图片使用了 HTTPS,所以需要设置 verify=False 来忽略 SSL 验证

# python sequential.py

2.2 多线程下载

workers = min(64, len(links)) 设置线程池中开启 64 个线程

# python threadpool.py

2.3 异步下载

使用 asyncioaiohttp 来实现异步网络 I/O

# python asynchronous.py

代码已上传到 https://github.com/wangy8961/python3-concurrency-pics-01 ,欢迎 star

未经允许不得转载: LIFE & SHARE - 王颜公子 » Python 3 爬虫|第10章:爬取少量妹子图

分享

作者

作者头像

Madman

如需 Linux / Python 相关问题付费解答,请按如下方式联系我

0 条评论

暂时还没有评论.