本帖最后由 sjc18627058721 于 2020-11-30 10:17 编辑
使用前需要安装相应的模块
新手上路,如果有不足,请大佬指出
[Python] 纯文本查看 复制代码 import re
import requests
import os
import easygui
(min,max)=easygui.multenterbox(fields=['起始数','终止数'],values=['26524','26526'])
min=int(min)
max=int(max)
os.mkdir('bizhi')
os.chdir('bizhi')
num=1
for i in range(min,max):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3760.400 QQBrowser/10.5.4083.400'
}
urls = "http://pic.netbian.com"
url = "http://pic.netbian.com/tupian/{}.html".format(str(i))
res=requests.get(url,headers=headers)
res.encoding='gbk'
html=res.text
image = re.findall('<img src="(.*?)" data-pic', html)
name = re.findall('<h1>(.*?)</h1>', html)
images = [urls + i for i in image]
for names in name:
for img in images:
file_name=names+'.jpg'
print("===========================开始下载第{0}张壁纸================================".format(num))
print(file_name)
response=requests.get(img)
with open(file_name,'wb') as file:
file.write(response.content)
print("下载完成")
num+=1 |