介绍
今天就跟大家聊聊有关HTMLParser模块怎么在python中使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
安装:
npm install HTMLParser
<强> HTMLParser提供构造函数:强>
function 解析器(处理器),{ this._handler =,才能处理程序; }
<>强HTMLParser解析HTML: 强>
得到html.parser import HTMLParser 得到html.entities import  name2codepoint class MyHTMLParser (HTMLParser): def 才能;handle_starttag(自我,,标签,attrs): ,,,print (& # 39; & lt; % s> & # 39;, %,标签) def 才能handle_endtag(自我,,标签): ,,,print (& # 39; & lt;/% s> & # 39;, %,标签) def 才能;handle_startendtag(自我,,标签,attrs): ,,,print (& # 39; & lt; % s/祝辞& # 39;,%,标签) def 才能handle_data(自我,,数据): ,,,印刷(数据) def 才能handle_comment(自我,,数据): ,,,print (& # 39; & lt; !——& # 39;,,数据,& # 39;——祝辞& # 39;) def 才能handle_entityref(自我,,名字): ,,,print (& # 39;, % s; & # 39;, %,名称) def 才能handle_charref(自我,,名字): ,,,print (& # 39;, # % s; & # 39;, %,名称) 时间=parser MyHTMLParser () parser.feed (& # 39; & # 39; & # 39; & lt; html> & lt; head> & lt;/head> & lt; body> & lt; !——, test html  parser ——比; & lt;才能p> Some & lt; https://www.yisu.com/a href=" #/"> html > html教程结束。
身体>