我试图用shutil/urlopen下载图像,因为不推荐?我不确定它是否被弃用,但urlretrieve不下载该文件,它只是创建映像名称的文件夹。看过其他问题后,我看到一个提供此代码的问题,但是我也发现了一个错误。下载Web图像瓦特/ urlopen/shutil:错误__exit__
from urllib2 import urlopen
from shutil import copyfileobj
url = 'http://www.watchcartoononline.com/thumbs/South-Park-Season-14-Episode-11-Coon-2-Hindsight.jpg'
path = 'image.jpg'
with urlopen(url) as in_stream, open(path, 'wb') as out_file:
copyfileobj(in_stream, out_file)
输出
with urlopen(url) as in_stream, open(path, 'wb') as out_file:
AttributeError: addinfourl instance has no attribute '__exit__
正如我在这个问题中所说的,urlretrieve不会工作,因为网站即时下载从它的图像不赞成 – Crispy
@Crispy:你确定不推荐使用你正在寻找的词吗? – Blender
我可能在术语上有错,因为我在编程方面的术语不太好。 – Crispy