标签:环境 col cto ima html src findall time 抓取
1,Python环境2,下面直接编写代码
import urllib
import re
import time
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
html = html.decode(‘utf-8‘)
return html
def getImgUrl(html):
str_re = r‘<img[^>]src[=\"\‘]+([^\"\‘])[\"\‘][^>]*>‘
imgre = re.compile(str_re,re.I)
imglist = re.findall(imgre,html)
for i in imglist:
urllib.urlretrieve(i,‘/mnt/test/‘+str(time.time())+".jpg")
#last setup is invocation and test it
html = getHtml(‘http://xxx.xxx.xxx‘)
getImgUrl(html)
标签:环境 col cto ima html src findall time 抓取
原文地址:http://blog.51cto.com/13718210/2134963