支持python3的快速html到文本解析器(文章可读性工具)
readability-lxml的Python项目详细描述
python可读性
给定一个html文档,它会取出主体文本并将其清理。
这是arc90’s readability project的ruby端口的python端口。
安装
使用pip很简单,只需运行:
$ pip install readability-lxml
使用量
>> import requests >> from readability import Document >> >> response = requests.get('http://example.com') >> doc = Document(response.text) >> doc.title() >> 'Example Domain' >> doc.summary() >> u'<html><body><div><body id="readabilityBody">\n<div>\n <h1>Example Domain</h1>\n <p>This domain is established to be used for illustrative examples in documents. You may use this\n domain in examples without prior coordination or asking for permission.</p> \n <p><a href="http://www.iana.org/domains/example">More information...</a></p>\n</div> \n</body>\n</div></body></html>'
更改日志
- 0.7.1对Python3.7的支持。修复了处理具有大量空格的文档时的速度减慢问题。
- 0.7改进了HTML5标签处理。修复了剥离不需要的HTML节点(以前只删除了第一个匹配的节点)。
- 0.6最终是一个支持python版本2.6、2.7、3.3-3.6的版本
- 0.5准备一个版本以支持python版本2.6、2.7、3.3和3.4
- 0.4添加视频加载,允许每个段落有更多图像
- 0.3添加了document.encoding、positive_keywords和negative_keywords
许可
此代码在the Apache License 2.0许可证下。
感谢
- 最新readability.js
- Starrhorne和IterationLabs的Ruby端口
- Python port作者:gfxmonk
- 减少工作量<;http://www.minvolai.com/blog/decruft-arc90s-readability-in-python/>;移动到lxml
- “br to p”修复readability.js,提高了较小文本的质量
- GitHub用户贡献。