for url in urls:
print(url)
time.sleep(1)
file_name = url.split("/")[-1]
request = urllib.request.Request(url, headers=head)
respons = urllib.request.urlopen(request)
print(type(respons))
with open(file_name,'wb') as f:
f.write(respons.content)
错误提示:
f.write(respons.content)
AttributeError: 'HTTPResponse' object has no attribute 'content'
链接是jpg格式的,怎么修改吖。
去掉content,提示:
f.write(respons)
TypeError: a bytes-like object is required, not 'HTTPResponse'