Я перебираю список URL для изображений.
import requests
list_url = ["www.abc.com/def.jpg", " www.abc.com/def1.jpg",... "www.abc.com/def100000.jpg"]
correct_img_list = []
for img in list_url:
request = requests.get(img)
if request.status_code == 200:
correct_img_list.append(img)
continue
else:
continue
i = 1
for img in correct_img_list:
urllib.request.urlretrieve(img, "local_image file_" + str(i))
i += 1
Я хочу, чтобы он go прошел по списку, захватил URL и затем загрузил изображение в локальный каталог.
Я вижу ошибку:
Traceback (most recent call last):
File "c:/Users/liuh9/Desktop/google chrome folder/image-downloader.py", line 714, in <module>
urllib.request.urlretrieve(img, "local_image file " + str(i))
File "C:\Users\liuh9\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 247, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "C:\Users\liuh9\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\liuh9\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\liuh9\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\liuh9\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\liuh9\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\liuh9\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
Большое спасибо!