1 #!usr/bin/env python 2 #-*- coding:utf-8 -*- 3 import urllib 4 import re 5 6 def getHtml(url): 7 page = urllib.urlopen(url) 8 html = page.read() 9 return html 10 11 def getImg(html): 12 reg = r‘src="http://.+\.jpg" class="img_pic_layer"‘ 13 imgre = re.compile(reg) 14 imglist = imgre.findall(html) 15 return imglist[0][5:-23] 16 17 html = getHtml("http://image.baidu.com/") 18 print getImg(html)
时间: 2024-10-09 06:11:16