Python 基于学习 网络小爬虫

<span style="font-size:18px;">#
# 百度贴吧图片网络小爬虫
#


import re
import urllib
 
def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
 
def getImg(html):
    reg = r'src="(.+?\.jpg)" pic_ext'
    imgre = re.compile(reg)
    imglist = imgre.findall(html)
    x = 0
    l=len(imglist)
    print "总共同拥有%d张图片"%(l)
    print "-------------------"
    for imgurl in imglist:
        print "第%d张图片" %(x+1)
        urllib.urlretrieve(imgurl,'E:\\Pythoncode\\picture\\%s.jpg' % x)
        x = x + 1       
    
html = getHtml("http://tieba.baidu.com/p/3093487131")
getImg(html)</span>
</pre><pre code_snippet_id="415913" snippet_file_name="blog_20140703_4_8970806" name="code" class="python">总共同拥有38张图片
-------------------
第1张图片
第2张图片
第3张图片
第4张图片
第5张图片
第6张图片
第7张图片
第8张图片
第9张图片
第10张图片
第11张图片
第12张图片
第13张图片
第14张图片
第15张图片
第16张图像
文章17图片
文章18图片
文章19图片
文章20图片
文章21图片
文章22图片
文章23图片
文章24图片
文章25图片
文章26图片
文章27图片
文章28图片
文章29图片
文章30图片
文章31图片
文章32图片
文章33图片
文章34图片
文章35图片
文章36图片
文章37图片
文章38图片



   
posted @ 2015-12-09 13:42  mengfanrong  阅读(287)  评论(0编辑  收藏  举报