由于已弃用,我正在尝试使用 shutil/urlopen 下载图像?我不确定它是否已弃用,但 urlretrieve 不会下载文件,它只是创建图像名称的文件夹。在查看了其他问题后,我看到了一个提供此代码的问题,但我也收到了一个错误。
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__