验证中...
本周日,苏州开源盛宴,一起聊聊:Devops、K8s、数据库建模、SoLiD、.Net Core、微信开发、去中心化… 点击占座。
gistfile1.txt
原始数据 复制代码
import requests
import os
from bs4 import BeautifulSoup
url = "http://www.mzitu.com"
Hostreferer = {
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'Referer': 'https://www.mzitu.com/'
}
Picreferer = {
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'Referer': 'https://www.mzitu.com/'
}
html = requests.get(url, headers=Hostreferer)
soup = BeautifulSoup(html.text, "html.parser")
pic_max = soup.find_all('a', class_='page-numbers')[3].text
path = 'I:/mzitu/'
if (os.path.exists(path)):
pass
else:
os.makedirs(path)
print('开始执行下载功能')
for i in range(1, int(pic_max) + 1):
href = url + '/xinggan/page/' + str(i)
html = requests.get(href, headers=Hostreferer)
mess = BeautifulSoup(html.text, "html.parser")
images = mess.find_all('img', class_='lazy')
for img in images:
file_name = img['data-original']
content = requests.get(file_name, headers=Picreferer).content
file_name = path + file_name[-20:]
with open(file_name, 'wb') as f:
f.write(content)
print('完成')

评论列表( 1 )

Ace 2019-03-16 15:41

666

你可以在登录后,发表评论

搜索帮助

14_float_left_people 14_float_left_close