![](/img/trans.png)
[英]Python, basic question: How do I download multiple url's with urllib.request.urlretrieve
[英]urllib.request.urlretrieve ERROR trying to download jpeg in Python
我正在嘗試使用Python 3.5.2中的urllib.request.urlretrieve(url,filename)下載.jpg文件。 網址為http://dm.victoriassecret.com/product/404x539/V603923_CROP1.jpg 。 引發以下錯誤: http.client.RemoteDisconnected:遠程終端關閉了連接,沒有響應 。
使用此網址嘗試同樣的操作時,我也遇到問題= http://lp2.hm.com/hmprod?set=source[/model/2017/9AS 0505882 002 00 0034.jpg],類型[STILLLIFE_FRONT]&hmver = 0&call = url [file:/ product / style] 。
在這種情況下,將引發以下錯誤: 引發HTTPError(req.full_url,code,msg,hdrs,fp)urllib.error.HTTPError:HTTP錯誤505:不支持HTTP版本
有誰知道這些網址有什么問題,我該如何解決? 與我分享您的知識,將非常高興。
遙控器沒有響應,因為您的請求中缺少標頭。 此外,我建議您使用requests
模塊(通過pip install requests
進行pip install requests
),因為它比urllib
更好,更快:
import requests
headers = headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Cafari/537.36'}
pic = requests.get('http://dm.victoriassecret.com/product/404x539/V603923_CROP1.jpg', headers=headers)
with open('beautiful.jpg', 'wb') as photo:
photo.write(pic.content)
現在打開您的工作目錄,您將找到駐留在其中的圖像。
這也將與您的其他鏈接一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.