# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python模块之HTMLParser(原理很大程度上就是对类构造的熟练运用) import HTMLParser
#tag是的html标签,attrs是 (属性,值)元组(tuple)的列表(list)。
#HTMLParser自动将tag和attrs都转为小写 '''
>>> help(HTMLParser)
Help on module HTMLParser:
CLASSES
exceptions.Exception(exceptions.BaseException)
HTMLParseError
markupbase.ParserBase
HTMLParser class HTMLParser(markupbase.ParserBase)
| Find tags and other markup and call handler functions.
|
| Usage:
| p = HTMLParser()#初始化
| p.feed(data)#feed()方法可以多次调用,也就是不一定一次把整个HTML字符串都塞进去,可以一部分一部分塞进去
#提供一些文本给解析器。在由完整元素组成的限度内进行处理,不完整的数据被缓冲直到更多的数据提供或者close()被调用
| ...
| p.close()
|
| Methods defined here:
|
| __init__(self)
| Initialize and reset this instance.
|
| check_for_whole_start_tag(self, i)
| # Internal -- check to see if we have a complete starttag; return end
| # or -1 if incomplete.
|
| clear_cdata_mode(self)
|
| close(self)
| Handle any buffered data.
|
| error(self, message)
|
| feed(self, data) #向分析器提供数据。
| Feed data to the parser.
|
| Call this as often as you want, with as little or as much text
| as you want (may include '\n').
|
| get_starttag_text(self)
| Return full source of start tag: '<...>'.
|
| goahead(self, end)
| # Internal -- handle data as far as reasonable. May leave state
| # and data to be processed by a subsequent call. If 'end' is
| # true, force handling all data as if followed by EOF marker.
|
| handle_charref(self, name) #处理特殊字符串,就是以&#开头的,一般是内码表示的字符
| # Overridable -- handle character reference
|
| handle_comment(self, data) #处理注释,处理<!--comment-->内的内容
| # Overridable -- handle comment
|
| handle_data(self, data) #处理数据,就是<xx>data</xx>中间的那些数据
| # Overridable -- handle data
|
| handle_decl(self, decl) #处理<!开头的,比如<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
| #文档类型声明,
# Overridable -- handle declaration
|
| handle_endtag(self, tag) #处理结束标签,</xx>
| # Overridable -- handle end tag
|
| handle_entityref(self, name) #处理一些特殊字符,以&开头的
| # Overridable -- handle entity reference
|
| handle_pi(self, data) #处理形如<?instruction>的东西
| # Overridable -- handle processing instruction
|
| handle_startendtag(self, tag, attrs) #处理开始标签和结束标签
| # Overridable -- finish processing of start+end tag: <tag.../>
|
| handle_starttag(self, tag, attrs) # 处理开始标签,比如<xx>
| # Overridable -- handle start tag
|
| parse_bogus_comment(self, i, report=1)
| # Internal -- parse bogus comment, return length or -1 if not terminated
| # see http://www.w3.org/TR/html5/tokenization.html#bogus-comment-state
|
| parse_endtag(self, i)
| # Internal -- parse endtag, return end or -1 if incomplete
|
| parse_html_declaration(self, i)
| # Internal -- parse html declarations, return length or -1 if not terminated
| # See w3.org/TR/html5/tokenization.html#markup-declaration-open-state
| # See also parse_declaration in _markupbase
|
| parse_pi(self, i)
| # Internal -- parse processing instr, return end or -1 if not terminated
|
| parse_starttag(self, i)
| # Internal -- handle starttag, return end or -1 if not terminated
|
| reset(self)
| Reset this instance. Loses all unprocessed data.
|
| set_cdata_mode(self, elem)
|
| unescape(self, s)
|
| unknown_decl(self, data)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CDATA_CONTENT_ELEMENTS = ('script', 'style')
|
| entitydefs = None
|
| ----------------------------------------------------------------------
| Methods inherited from markupbase.ParserBase:
|
| getpos(self)
| Return current line number and offset.
|
| parse_comment(self, i, report=1)
| # Internal -- parse comment, return length or -1 if not terminated
|
| parse_declaration(self, i)
| # Internal -- parse declaration (for use by subclasses).
|
| parse_marked_section(self, i, report=1)
| # Internal -- parse a marked section
| # Override this to handle MS-word extension syntax <![if word]>content<![endif]>
|
| updatepos(self, i, j)
| # Internal -- update line number and offset. This should be
| # called for each piece of data exactly once, in order -- in other
| # words the concatenation of all the input strings to this
| # function should be exactly the entire input. >>>
'''

python模块之HTMLParser(原理很大程度上就是对类构造的熟练运用)的更多相关文章

  1. QPointer很大程度上避免了野指针(使用if语句判断即可,类似于dynamic_cast),而且使用非常方便 good

    QPointer 如何翻译呢?我不太清楚,保留英文吧. The QPointer class is a template class that provides guarded pointers    ...

  2. python模块之HTMLParser之穆雪峰的案例(理解其用法原理)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser之穆雪峰的案例(理解其用法原理) #http://www.cnblog ...

  3. python模块介绍- HTMLParser 简单的HTML和XHTML解析器

    python模块介绍- HTMLParser 简单的HTML和XHTML解析器 2013-09-11 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq ...

  4. python模块之HTMLParser抓页面上的所有URL链接

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser抓页面上的所有URL链接 import urllib #MyParse ...

  5. python模块之HTMLParser解析出URL链接

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser解析出URL链接 #http://www.cnblogs.com/mf ...

  6. python模块之HTMLParser

    HTMLParser是python用来解析html的模块.它可以分析出html里面的标签.数据等等,是一种处理html的简便途径. HTMLParser采用的是一种事件驱动的模式,当HTMLParse ...

  7. tensorflow 单机多GPU训练时间比单卡更慢/没有很大时间上提升

    使用tensorflow model库里的cifar10 多gpu训练时,最后测试发现时间并没有减少,反而更慢 参考以下两个链接 https://github.com/keras-team/keras ...

  8. python模块学习---HTMLParser(解析HTML文档元素)

    HTMLParser是Python自带的模块,使用简单,能够很容易的实现HTML文件的分析. 本文主要简单讲一下HTMLParser的用法. 使用时需要定义一个从类HTMLParser继承的类,重定义 ...

  9. 新学了几个python模块,不是很鸡肋。

    先说一个模块分类(基本上所有模块都是小写开头,虽然规范的写法是变量的命名规范,但是,都是这样写的) 1,C编写并镶嵌到python解释器中的内置模块 2,包好的一组模块的包 3.已经被编译好的共享库, ...

随机推荐

  1. Can't create pdf file with font calibri bold 错误解决方案

    错误情况: %%[ ProductName: Distiller ]%% Mangal not found, using Courier. %%[ Error: invalidfont; Offend ...

  2. Intel的AVX2指令集解读

    原文链接:http://blog.csdn.net/vbskj/article/details/38408213 在Intel Sandy Bridge微架构中,Intel引入了256位SIMD扩展A ...

  3. [Link]Gearman分布式任务处理系统

    http://blog.csdn.net/jiao_fuyou/article/category/1745977 http://www.cnblogs.com/cocowool/archive/201 ...

  4. springBoot注解大全JPA注解springMVC相关注解全局异常处理

    https://www.cnblogs.com/tanwei81/p/6814022.html 一.注解(annotations)列表 @SpringBootApplication:包含了@Compo ...

  5. cocos2d-js中Chipmunk物理引擎相关(1)

    近期看些cocos2d-js的东西.用到当中的Chipmunk的一些东西.由于相关的资料也不是非常具体,所以看到一些东西实用就记录下来. 1. chipmunk是cocos2d的一个一个物理引擎.用来 ...

  6. GIS原理学习目录

    GIS原理学习目录 内容提要 本网络教程是教育部“新世纪网络课程建设工程”的实施课程.系统扼要地阐述地理信息系统的技术体系,重点突出地理信息系统的基本技术及方法. 本网络教程共分八章:第一章绪论,重点 ...

  7. System.Diagnostics.Debug和System.Diagnostics.Trace

    在 .net 类库中有一个 system.diagnostics 命名空间,该命名空间提供了一些与系统进程.事件日志.和性能计数器进行交互的类库.当中包括了两个对开发人员而言十分有用的类——debug ...

  8. 如何配置官方peerDroid,使其运行起来

    一.Peer Droid是JXME协议到android平台的移植,开发者可以利用它来实现android设备以及传统PC机通讯的应用程序,peerDroid的官方demo主要是实现PC端peer和and ...

  9. Eclipse导入GitLab中指定分支的项目

    一.如果主分支丢失,是否可以恢复其他分支? 答案是可以的,下面我们就拿恢复分支publish-2018-6-5来说明问题,最终实现把分支publish-2018-6-5还原成项目放到Eclipse中 ...

  10. LogCat用法2

    如果adb devices显示设备的状态是offline, 这是可以看手机的通知栏,会有一个"触摸以设置USB"这样一个类似的提示,触摸它以后会要求你选择USB的用途,选择第二个' ...