Skip to content

Instantly share code, notes, and snippets.

@dervn
Created February 25, 2012 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dervn/1906384 to your computer and use it in GitHub Desktop.
Save dervn/1906384 to your computer and use it in GitHub Desktop.
python下载网络上的图片示例
import urllib
import urllib2
import os
picurl="http://images.51cto.com/files/uploadimg/20100630/104906665.jpg"
save_path="d:\\"
imgData = urllib2.urlopen(picurl).read()
# 给定图片存放名称
fileName = save_path + "\\ddd.jpg"
# 文件名是否存在
if os.path.exists(fileName):
output = open(fileName,'wb+')
output.write(imgData)
output.close()
print "Finished download \n"
print "运行完成"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment