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.已经被编译好的共享库, ...
随机推荐
- Error:Program type already present: android.arch.lifecycle.LiveData
Apparently, this is intended behavior: com.firebaseui:firebase-ui-firestore:3.1.0 depends on android ...
- 微服务中的 API 网关(API Gateway)
API 网关(API Gateway)提供高性能.高可用的 API 托管服务,帮助用户对外开放其部署在 ECS.容器服务等云产品上的应用,提供完整的 API 发布.管理.维护生命周期管理.用户只需进行 ...
- 使用idea 在springboot添加本地jar包的方法 部署的时候本地jar没有包含的解决方法
需要添加dependency 和resources 否则发布的时候可能会缺少jar <dependency> <groupId>com.sap</groupId> ...
- float,double等精度丢失问题 float,double内存表示
问题提出:12.0f-11.9f=0.10000038,"减不尽"为什么? 来自MSDN的解释: http://msdn.microsoft.com/zh-cn/c151dt3s. ...
- c++实现Xml和json互转【转】
https://blog.csdn.net/kfy2011/article/details/51774242 1.下载c语言的cJson库源码,库很小,只有两个文件cJSON.c和cJSON.h.下载 ...
- 魅族推送 简介 集成 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 华为推送 简介 集成 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Android adb你真的会用吗?
引言 本文基于Android官方文档, 以及个人工作的使用经验, 总结下adb的常用用法, 备忘. 1, adb简介 adb全名Andorid Debug Bridge. 顾名思义, 这是一个Debu ...
- Ubuntu环境变量解析
在Ubuntu中有如下几个文件可以设置环境变量 /etc/profile:在登录时,操作系统定制用户环境时使用的第一个文件,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. /e ...
- 深度学习(Deep Learning)算法简介
http://www.cnblogs.com/ysjxw/archive/2011/10/08/2201782.html Comments from Xinwei: 最近的一个课题发展到与深度学习有联 ...