- 授权协议: MIT
- 开发语言: Python
- 操作系统: 跨平台
- 软件首页: http://code.google.com/p/tagparser/
软件介绍
很多人需要提取网页的一些内容, 可以利用正则表达式提取,也可以用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()
输出一个网页的新闻.
Learn Python the Hard Way
Zed Shaw / Example Product Manufacturer / 2011
This is a very beginner book for people who want to learn to code. If you can already code then the book will probably drive you insane. It's intended for people who have no coding chops to build up t......一起来看看 《Learn Python the Hard Way》 这本书的介绍吧!
