zoukankan      html  css  js  c++  java
  • 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图片


    
       
    
  • 相关阅读:
    PSR
    php类与对象
    二进制、位运算及其用处
    安装LNMP笔记
    计算机基础
    Python3编写HFS(CVE2014-6287)检测脚本
    windows和iis对应版本关系
    phpStudy8.1.0.1配置子域名多网站
    Xml外部实体注入
    xss小游戏通关-全答案
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5032567.html
Copyright © 2011-2022 走看看