Python的HTML文档解析 tagparser

码农软件 · 软件分类 · HTML解析器 · 2019-04-03 10:56:48

软件介绍

很多人需要提取网页的一些内容, 可以利用正则表达式提取,也可以用beautifulsoap等工具. 正则表达式方法速度快,缺点是不好找到匹配的正则. 其他类似beautiful的工具因为要全面分析html,而html不像xml那么严格,语法比较复杂所以效率很糟糕.这个工具就是为了处里这种问题 的.

这个工程只有一个文件 .tagparser.py 它可以方便分析像xml html 等这种标记语言. 只要他是'<'和'>'括起来的标记语言.

分析的方式是'抽'式的.也就是说扫描一个个字符 当遇到一个tag时 也就是遇到一个<>的时候,回调一个函数onGetTag() ,可以重载这个函数做自己的处理.

如遇到

回调 onGetTag(tagstr, tagstro). tagstr = p tagstro = P tagstr 是小写的tag tagstro是源文件的大小写状态

遇到内容 回调 onGetTxt(txtstr) , txtstr是 如:<tag>xxxxxxxxx</tag> xxxxx即内容

使用例子,提取网易新闻页的主要内容,新闻 标题,内容主体: 例如:

p = TagParser()
p
.fetchUrl('http://news.163.com/09/0117/04/4VR79MP60001124J.html')
p
.printResult()

输出一个网页的新闻.

本文地址:https://www.codercto.com/soft/d/2759.html

Measure What Matters

Measure What Matters

John Doerr / Portfolio / 2018-4-24 / GBP 19.67

In the fall of 1999, John Doerr met with the founders of a start-up he’d just given $11.8 million, the biggest investment of his career. Larry Page and Sergey Brin had amazing technology, entrepreneur......一起来看看 《Measure What Matters》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试