# -*- 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. SVG渲染顺序及z轴显示问题(zIndex)

    SVG是严格按照定义元素的顺序来渲染的,这个与HTML靠z-index值来控制分层不一样. 在SVG中,写在前面的元素先被渲染,写在后面的元素后被渲染.后渲染的元素会覆盖前面的元素,虽然有时候受透明度 ...

  2. JavaScript:sort() 方法

    ylbtech-JavaScript:sort() 方法 JavaScript sort() 方法 1. 定义和用法返回顶部 sort() 方法用于对数组的元素进行排序. 语法 arrayObject ...

  3. VS2010 SP1安装失败之”此计算机的状态不支持此安装“()

    升级安装VS2010SP1的时候,出现“此计算机的状态不支持此安装”,Google得之: 如下图显示: 安装程序已经检测到,此计算机不满足安装此软件所需的条件.必须先解决以下这些造成阻止的问题,才可以 ...

  4. Tensorflow 模型持久化saver及加载图结构

    主要内容: 1. 直接保存,加载模型; (可以指定加载,保存的var_list) 2. 加载,保存指定变量的模型 3. slim加载模型使用 4. 加载模型图结构和参数等 tensorflow 恢复部 ...

  5. 发布一个高效的JavaScript分析、压缩工具 JavaScript Analyser

    发布一个高效的JavaScript分析.压缩工具 JavaScript Analyser 先发一段脚本压缩示例,展示一下JSA语法压缩和优化功能. try { //xxxx(); } catch (e ...

  6. 前端性能优化:配置ETag

    什么是ETag? 实体标签(EntityTag)是唯一标识了一个组件的一个特定版本的字符串,是web服务器用于确认缓存组件的有效性的一种机制,通常可以使用组件的某些属性来构造它. 条件GET请求 浏览 ...

  7. 如何对 GIT 分支进行规划?

    项目背景: 该项目是在2011年11月份使用Asp.net三层帮荷兰某个客户开发的机票预定系统 该客户主要是做中国与欧洲的旅行社业务,特别是最近两年由于中国的发展因此客户也越来越重视机票业务 于是他们 ...

  8. SharePoint CAML Query小结

    CAML的结构. <View Type="HTML" Name="Summary"> <ViewBody ExpandXML="TR ...

  9. [Algorithm] Search element in a circular sorted array

    function findInCircularlySortedAry (ary = [], target) { ) { ; } ) { ] === target ? : -; } let , high ...

  10. Springmvc 服务器端文件下载

    转自:http://blog.csdn.net/boneix/article/details/51303280 业务场景:点击下载后直接保存而不是打开 解决代码:前端传入url /** * 返回流 * ...