python模块之HTMLParser(原理很大程度上就是对类构造的熟练运用)
# -*- 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(原理很大程度上就是对类构造的熟练运用)的更多相关文章
- QPointer很大程度上避免了野指针(使用if语句判断即可,类似于dynamic_cast),而且使用非常方便 good
QPointer 如何翻译呢?我不太清楚,保留英文吧. The QPointer class is a template class that provides guarded pointers ...
- python模块之HTMLParser之穆雪峰的案例(理解其用法原理)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser之穆雪峰的案例(理解其用法原理) #http://www.cnblog ...
- python模块介绍- HTMLParser 简单的HTML和XHTML解析器
python模块介绍- HTMLParser 简单的HTML和XHTML解析器 2013-09-11 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq ...
- python模块之HTMLParser抓页面上的所有URL链接
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser抓页面上的所有URL链接 import urllib #MyParse ...
- python模块之HTMLParser解析出URL链接
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python模块之HTMLParser解析出URL链接 #http://www.cnblogs.com/mf ...
- python模块之HTMLParser
HTMLParser是python用来解析html的模块.它可以分析出html里面的标签.数据等等,是一种处理html的简便途径. HTMLParser采用的是一种事件驱动的模式,当HTMLParse ...
- tensorflow 单机多GPU训练时间比单卡更慢/没有很大时间上提升
使用tensorflow model库里的cifar10 多gpu训练时,最后测试发现时间并没有减少,反而更慢 参考以下两个链接 https://github.com/keras-team/keras ...
- python模块学习---HTMLParser(解析HTML文档元素)
HTMLParser是Python自带的模块,使用简单,能够很容易的实现HTML文件的分析. 本文主要简单讲一下HTMLParser的用法. 使用时需要定义一个从类HTMLParser继承的类,重定义 ...
- 新学了几个python模块,不是很鸡肋。
先说一个模块分类(基本上所有模块都是小写开头,虽然规范的写法是变量的命名规范,但是,都是这样写的) 1,C编写并镶嵌到python解释器中的内置模块 2,包好的一组模块的包 3.已经被编译好的共享库, ...
随机推荐
- diff详解
作者: 阮一峰 日期: 2012年8月29日 diff是Unix系统的一个很重要的工具程序. 它用来比较两个文本文件的差异,是代码版本管理的基石之一.你在命令行下,输入: $ diff <变动前 ...
- Hadoop2.6.0版本号MapReudce演示样例之WordCount(一)
一.准备測试数据 1.在本地Linux系统/var/lib/hadoop-hdfs/file/路径下准备两个文件file1.txt和file2.txt,文件列表及各自内容例如以下图所看到的: wate ...
- DBS-Tally book(记账本)
ylbtech-dbs:DBS-Tally book(记账本) -- =============================================-- 记账本-- 模仿小程序“记账e”业 ...
- [置顶] 不刷机让越狱后的iphone恢复出厂设置
iphone越狱后,设置里的清除所有内容和设置选项是不生效的,选上之后菊花转个不停,只能强制退出,还有白苹果的危险. 若想恢复出厂设置有两个办法: 一.刷机 最直接的办法,我觉得itunes配合ito ...
- [leetcode]Clone Graph @ Python
原题地址:https://oj.leetcode.com/problems/clone-graph/ 题意:实现对一个图的深拷贝. 解题思路:由于遍历一个图有两种方式:bfs和dfs.所以深拷贝一个图 ...
- 关于XSuperMES项目使用的AChartEngine图表引擎
非常多时候项目中我们须要对一些统计数据进行绘制表格,更多直观查看报表分析 结果. 基本有以下几种方法: 1:能够进行android api进行draw这种话.效率比較低 2:使用开源绘表引擎, ...
- assetbundle 对自定义shader的打包
http://docs.unity3d.com/Manual/managingassetdependencies.html Managing asset dependencies Any give ...
- Sublime Es6教程1-环境搭建
因为现在网上的教程都不靠谱,于是决定自己跳坑自己写,分为三块来玩: 一.环境搭建 二.语法讲解 三.项目实战 很多时候,你想搞一个东西,却因为环境没有搭建好,而不能很开森的探索未知的世界,多年的编程经 ...
- Lanczos Algorithm and it's Parallelization Stragegy
由于写了降维的一个系列算法分析,本来以为对这个Lanczos算法会理解一点,但是还是不知道讲了什么,最多的就是会如何调用,然后出结果,所以就翻译官网的相关内容.本篇翻译来自Dimensional Re ...
- VMware vCloud Director network ports diagram
see:http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&exter ...