验证中...
gistfile1.txt
原始数据 复制代码
# coding:utf8
import os
import urllib.request
import re
_path = "D:\\doubanimage"
def save_file(path):
# 检查当前路径的有效性
if not os.path.isdir(_path):
os.mkdir(_path)
# 设置每个图片的路径
pos = path.rindex('/')
t = os.path.join(_path,path[pos+1:])
return t
root_url = "https://www.douban.com/"
headers = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"}
req = urllib.request.Request(url=root_url, headers=headers)
res = urllib.request.urlopen(req)
data = res.read()
for link,t in set(re.findall(r'(https:[^s]*?(jpg|png|gif))', str(data))):
print(link)
try:
urllib.request.urlretrieve(link, save_file(link))
except:
print('失败')

评论列表( 0 )

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

搜索帮助