爬虫,抓取网页图片

 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)

 

posted on 2015-04-07 11:31  GreenBean  阅读(206)  评论(0编辑  收藏  举报

导航