直接下载不了,需要是教育机构邮箱,由于我没有,所以只能通过它给的链接爬取
import requests
import urllib.request
import time#导入包
import os
file=open("C:\\Users\\user\\Desktop\\image.txt",encoding="utf-8")
for i,line in enumerate(file):
try:
print(i)
if i<472:
continue
if os.path.exists("./data1/{}.jpg".format(i)):
print("file exist")
continue
web = urllib.request.urlopen(line)
time.sleep(0.5)#设置时间间隔为3秒
data = web.read()
f = open("./data1/{}.jpg".format(i),"wb")
f.write(data)
f.close()
except:
continue
最后虽然爬取到了,但是大部分都是打不开的图片,由于给的链接的网站有些需要登录或是其他原因导致的把