nes*_*esi 4 python urllib python-requests urlretrieve
我正在尝试使用Python 3.5.2 中的urllib.request.urlretrieve(url, filename)下载 .jpg 文件。网址是http://dm.victoriassecret.com/product/404x539/V603923_CROP1.jpg。引发以下错误: http.client.RemoteDisconnected: 远程端关闭连接没有响应。
我在尝试使用此 url = http://lp2.hm.com/hmprod?set=source[/model/2017/9AS 0505882 002 00 0034.jpg],type[STILLLIFE_FRONT]&hmver=0&call时也遇到问题=url[文件:/产品/风格]。
在这种情况下,会引发以下错误:raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 505: HTTP Version not support
有谁知道这些网址有什么问题以及如何解决它?与我分享你的知识,那就太好了。
遥控器没有响应,因为您的请求中缺少标头。此外,我建议您使用该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)
Run Code Online (Sandbox Code Playgroud)
现在打开您的工作目录,您会发现图像驻留在其中。
这也适用于您的其他链接。
| 归档时间: |
|
| 查看次数: |
2254 次 |
| 最近记录: |