网络爬虫 -- 批量下载网站图片

1. 准备

2. 开始工作

import requests
from bs4 import BeautifulSoup

res = requests.get('http://jandan.net/ooxx')
html = BeautifulSoup(res.text, "html.parser")

for index, each in enumerate(html.select('img')):
    with open('{}.jpg'.format(index), 'wb') as jpg:
        jpg.write(requests.get(each.attrs['src'], stream=True).content)

3.后记

python的库很多,写小工具的时候可以优先考虑python语言。需要什么功能只需要在网上搜索一下,基本上都有相应的模块,至于模块的说明只需要搜索下google,一般的用法基本上都能明白

原文地址:https://www.cnblogs.com/zjzyh/p/5443747.html