我試圖用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