Skip to content

Instantly share code, notes, and snippets.

@edwardwbli
Created February 23, 2012 17:18
Show Gist options
  • Save edwardwbli/1893882 to your computer and use it in GitHub Desktop.
Save edwardwbli/1893882 to your computer and use it in GitHub Desktop.
Google image downloader
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,os,re,urllib
folder="e:\image\\"
reg=re.compile("((?<=imgurl=)http.*?\.(jpg|gif|png|bmp|jpeg))")#正则表达式匹配下载地址
reg2=re.compile("((?<=/)[^/]*?\.(jpg|gif|png|bmp|jpeg))")
fd=open('image.htm','r')
html=fd.read()
fd.close()
results=reg.findall(html)
#print results
for img_link,value in results:
print img_link
s = reg2.search(img_link)
filename = folder+str(s.group())
print filename
try:
rt=urllib.urlretrieve(img_link,filename)
except Exception,e:
print e
# else:
# break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment