Python-如何从互联网上获取图像 [英] Python -- how to grab images off the internet

查看:58
本文介绍了Python-如何从互联网上获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从已知网址中抓取图片,然后使用Python(v2.6)将其保存到计算机中?谢谢

How can I grab a picture off of a known url and save it to my computer using Python (v2.6)? Thanks

推荐答案

您可以使用 urllib.urlretrieve .

You can use urllib.urlretrieve.

如有必要,将URL表示的网络对象复制到本地文件.

Copy a network object denoted by a URL to a local file, if necessary.

示例:

>>> import urllib
>>> urllib.urlretrieve('http://i.imgur.com/Ph4Xw.jpg', 'duck.jpg')
('duck.jpg', <httplib.HTTPMessage instance at 0x10118e830>)
# by now the file should be downloaded to 'duck.jpg'

这篇关于Python-如何从互联网上获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆