首先说一下,我用的是python 2.7,刚好在学Python,今天想去爬点图片当壁纸,但是当我用 SGMLParser 做 <img> 标签解析的时候,发现我想要的那部分根本没获取到,我尝试用 lxml 修复网页,还是解析不出..但是当我把此部分字段单独提出来时,我却可以将此部分标签解析出来,实在无法解决这个问题...先将问题放在这里,用正则表达式去匹配好了..如果有遇到过此问题的前辈请务必告诉我..我的邮箱是 781512880@qq.com

这是源网站:http://mcyacg.com/m60948/

<div class="quote"><blockquote><font size=""><font color="Pink">P站引言:</font></font>正好可以放在手心里的红色果实——“苹果”。红色果实切开后看起来像心形的苹果,在白雪公主、亚当与夏娃等故事中都是作为诱惑的象征登场。艳丽的红色外皮包裹着香甜多汁的清脆果实,或许有着一种不可思议的魅力吧。<br/>
今天,就为大家送上描绘了“苹果”的插画作品特辑。敬请欣赏这些仿佛能听见咬下新鲜苹果时的清脆声音的插画作品。</blockquote></div><br/>
<a href="http://pan.baidu.com/s/1mhJ4ti4" target="_blank"><font size="">下载</font></a><br/>
<img id="aimg_IPKD8" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i4.qlshw.org/08859a09d120090cfff30152010130c7.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_Sv2k2" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i4.qlshw.org/db3a060b649a422a701dd47982f9cbe5.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_Ob8zD" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i4.qlshw.org/8fd5b9b5f4706b17e71c00939c75f648.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_MWOuz" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i2.qlshw.org/7b5f4a94fff33ea1a7cac45131f2ba41.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_nG9jr" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i3.qlshw.org/4c0a17365342ef700c68c4e4caada0e0.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_J790D" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i2.qlshw.org/a1f2a3486ce679f007abea46782a33b7.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_v6mTz" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i4.qlshw.org/8d37e5d40f34c03180080135e8757bc8.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_wzFQq" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i2.qlshw.org/7feed5d205b6811d5d1366dd495a0760.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_xWlS5" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i2.qlshw.org/413f8d116e31174451032abfa72c1246.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_O8T03" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i4.qlshw.org/f654b77544edfeee9cda4d069e704c90.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_PfGhH" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i2.qlshw.org/e6fb8b6eafd5ef5dea2a13a284ba8309.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_tZEBu" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i3.qlshw.org/46d344876774e7dcb059ef84e2fc70f7.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_PnP6y" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i1.qlshw.org/9c6ab03cffb678a0945dcb0da127ea63.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_H01fi" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i1.qlshw.org/d0bf9d03f427a730b40a29bfebc9697a.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_j1pqX" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i3.qlshw.org/36074139da9039d1d4c0d1042f6b1b8c.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_xaHP0" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i3.qlshw.org/a40f503868cdd657531cbea34adf55e6.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_wE44O" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i1.qlshw.org/0a5d24a51f5c4ad0041d8feec5b5fe9a.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_T50cd" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i3.qlshw.org/b9f666b571221894bd4d922d369fce5d.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_C4o7y" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i4.qlshw.org/114b3eff9da458cfbfb52d08160fd30a.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<img id="aimg_m2c3s" onclick="zoom(this, this.src, 0, 0, 0)" class="zoom" file="http://i3.qlshw.org/ba3265f867650ef35891f6cb09a7a196.jpg" onmouseover="img_onmouseoverfunc(this)" lazyloadthumb="" border="" alt=""/><br/>
<br/>

这部分是我想要提取的元素.

from sgmllib import SGMLParser
class LableParse(SGMLParser):
def reset(self):
SGMLParser.reset(self)
self.level = 0
self.flag = False
self.picturesrc=[]
def start_div(self,attrs):
if self.flag == True: #遇到子层 level+1
self.level+=1
for k,v in attrs:
if k=='class' and v=='pct':
self.flag = True
self.level+=1 #自己加一层 def end_div(self):
if self.level == 0:
self.flag = False
if self.flag == True: #退出DIV子层的时候level-1
self.level-=1
def start_img(self,attrs):
#if self.flag == True:
for k,v in attrs:
print '{%s : %s}'%(k,v) if __name__ == '__main__':
lp = LableParse()
lp.feed(open('source.txt').read())

这部分是我继承自 SGMLParser 的一个类..

Python SGMLParser 的1个BUG??的更多相关文章

  1. python for android : BeautifulSoup 有 bug

    BeautifulSoup 善于网页数据分析 .可是 python for android : BeautifulSoup 有 bug , text = h4.a.text 仅仅能取得 None,因此 ...

  2. 从BUG工具redmine上获取数据后借助python模块pycha 画出BUG分析类报表

    整体代码比较冗长,但是很好读.写的方法全是按照BUG分类去写的.所以写死了,凑合看吧,画出饼图,树状图和生成对应的数据excel,希望大家举一反三能帮助自己分析BUG #__author__ = 'x ...

  3. python二叉树染色-有严重BUG

    #coding:utf-8 ''' 二叉树涂黑 输入: 5 2 1 -1 4 2 -1 5 4 -1 3 1 1 2 输出: 3 第二题是:斗地主 ''' import sys b=list() cl ...

  4. Python UnicodeDecodeError

    出于对goagent的兴趣,看了python,后来又想了解一下gae,于是就按照gae python创建hello world应用程序,可是一开始就遇到这样一个问题: UnicodeDecodeErr ...

  5. python urllib模块

    1.urllib.urlopen(url[,data[,proxies]]) urllib.urlopen(url[, data[, proxies]]) :创建一个表示远程url的类文件对象,然后像 ...

  6. 扩展Python模块系列(四)----引用计数问题的处理

    承接上文,发现在使用Python C/C++ API扩展Python模块时,总要在各种各样的地方考虑到引用计数问题,稍不留神可能会导致扩展的模块存在内存泄漏.引用计数问题是C语言扩展Python模块最 ...

  7. BUG心得

    在<程序员,你会从 Bug 中学习么?>一文中,我写了我是怎样追踪这些年遇到的最有趣 bug 的.最近我重新浏览了这所有的 194 个条目(历时 13 年),看看我从这些 bug 中学到了 ...

  8. 无限遍历,Python实现在多维嵌套字典、列表、元组的JSON中获取数据

    背景 在做接口自动化的过程中,接口返回的数据是  列表字典循环嵌套  格式的,所以怎样通过一个key值,获取到被包裹了多层的目标数据成为了摆在我面前的一个问题. 一开始没想自己写,但是搜索后发现虽然很 ...

  9. Python中的对象引用、浅拷贝与深拷贝

    最近项目中遇到一个Python浅拷贝机制引起的bug,由于对于Python中对象引用.赋值.浅拷贝/深拷贝机制没有足够的认识,导致调试了很久才发现问题,这里简单记录一下相关概念. 在Python的设计 ...

随机推荐

  1. 使用 xhprof 进行 php 的性能分析

    基于本机环境(php7,macos) 1.xhprof 扩展 php7 下安装 xhprof 扩展: git clone https://github.com/longxinH/xhprof cd x ...

  2. Zabbix应用四:Zabbix监控Nginx

    利用Zabbix监控Nginx 一.准备nginx监控模版: 1.1.下载nginx监控模版:  点此下载 1.2.导入模版: Zabbix管理页面,选择'配置'->'模版'->'导入': ...

  3. srpingboot2 session过期时间设置

    springboot2 设置session过期的配置 server.servlet.session.timeout = 1800 而不再是 server.session.timeout=1800

  4. iOS二维码扫描的实现(Swift)

    随着二维码的普遍使用,二维码扫描也成为了很多app的一个基本功能,本篇主要来介绍一下如何实现一个简单的二维码扫描功能.本文使用了XCode自带的AVFoundation 库,利用Swfit语言实现. ...

  5. SVN 使用笔记

    SVN中检出 和 导出 的区别 检出得到的文件夹中,是受SVN客户端控制的,对其进行文件或文件夹的增删改操作都会被SVN客户端识别出来,对其可以进行update.commit操作.其中含有.svn隐藏 ...

  6. 多年前写的DataTable与实体类的转换

    介绍 介绍 很多年前一直使用Ado.net,后来慢慢转型到其他的orm,在转型过程中,有意向将两者的模型结合起来,利用DataTable中的行状态完善一些mvc中的数据控制作用.现在把它放出来,留个纪 ...

  7. 微服务深入浅出(7)-- 网关路由Zuul

    Zuul用于构建边界服务,致力于动态路由,过滤,监控,弹性伸缩和安全等方向. 1.Zuul+Ribbon+Eureka结合,可以实现智能路由和负载均衡 2.网关将所有服务的API接口统一聚合统一暴露 ...

  8. RW RO ZI ROM keil中的含义

    编译的一个ARM的程序,会得到这样的信息: ============================================================================== ...

  9. mysql只读模式的设置方法与实验【转】

    在MySQL数据库中,在进行数据迁移和从库只读状态设置时,都会涉及到只读状态和Master-slave的设置和关系. 经过实际测试,对于MySQL单实例数据库和master库,如果需要设置为只读状态, ...

  10. Focal Loss笔记

    论文:<Focal Loss for Dense Object Detection> Focal Loss 是何恺明设计的为了解决one-stage目标检测在训练阶段前景类和背景类极度不均 ...