这太傻了。每次我尝试下载一组在文件名中有句点的图像时,图像在下载后显示为“无效”,并且无法在我的机器上正常打开。以前从未遇到过这个问题。是什么赋予了?我该如何解决这个问题?
image_url = "http://somewebsite.com/images/icon.50.png"
urllib.urlretrieve(image_url, "icon.png")
答案 0 :(得分:0)
也许文件足够大......
试试这个
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
return local_filename