Skip to content

Instantly share code, notes, and snippets.

@omengye
Created September 25, 2014 14:05
Show Gist options
  • Select an option

  • Save omengye/bf02973e08978c4f41dd to your computer and use it in GitHub Desktop.

Select an option

Save omengye/bf02973e08978c4f41dd to your computer and use it in GitHub Desktop.
urllib2 下载图片
# -*- coding: utf-8 -*-
import urllib2
import os
a = [u'http://mmbiz.qpic.cn/mmbiz/ibfSwYkJfj0vnkpJYcVzcjQZTnib6Uyjz1yhy3adXD5n0xkKgrPs9Daic1ibmUUM1ibOBQWDuYoCnl2Cia2NlF6BvyEw/0']
print u'总计' + str(len(a))
pic_path = os.getcwd() +'\\\\' + 'pic'
i = 0
for url in a:
socket = urllib2.urlopen(url)
data = socket.read()
with open(pic_path + '\\\\' + url.split('/')[4] + '.jpg', "wb") as jpg:
jpg.write(data)
socket.close()
i += 1
print u'第' + str(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment