import requests
import os
def download_media(media_url):
current_path = media_url[media_url.find('wikiimage/')+10:]
os.makedirs('/'.join(current_path.split('/')[:-1]), exist_ok=True)
with open(current_path, 'wb',) as f:
r = requests.get(media_url,
headers={'Referer':'https://www.zgbk.com/ecph/words?SiteID=1&ID=180450&Type=bkzyb&SubID=138634'})
if r.status_code == 200:
f.write(r.content)
else:
print(r.text)
if __name__ == '__main__':
with open('图片地址0.txt', 'r',encoding="utf8") as f: # 网址文件
urls = f.readlines()
for url in urls:
download_media(url[:-1])
Traceback (most recent call last):
File "F:\图片下载\多线程下载.py", line 11, in <module>
with open(img1,'r') as f1:
FileNotFoundError: [Errno 2] No such file or directory: ''
进程已结束,退出代码为 1
Traceback (most recent call last):
File "F:\图片下载\img1\000.py", line 32, in <module>
with open(imgname,"ab") as f3:
FileNotFoundError: [Errno 2] No such file or directory: 'd:\\cihai7\\upload\\wordresources\\wikiimage\\2021\\06\\07\\%E5%BE%B7%E7%89%B9%E7%94%BB%E5%83%8F%EF%BC%8C%E7%8E%B0%E8%97%8F%E5%8A%A0%E5%B0%94%E5%90%84%E7%AD%94%E7%BB%B4%E5%A4%9A%E5%88%A9%E4%BA%9A%E7%BA%AA%E5%BF%B5%E5%A0%82%EF%BC%88victoriamemorial%EF%BC%89(%E5%9B%BE%E7%89%87%E6%8F%90%E4%BE%9B%E8%80%85%E5%BE%85%E6%9F%A5)_thumbnail.jpg'
进程已结束,退出代码为 1