一种ht/xml web抓取工具
libextract的Python项目详细描述
___ __ __ __ / (_) /_ ___ _ __/ /__________ ______/ /_ / / / __ \/ _ \| |/_/ __/ ___/ __ `/ ___/ __/ / / / /_/ / __/> </ /_/ / / /_/ / /__/ /_ /_/_/_.___/\___/_/|_|\__/_/ \__,_/\___/\__/
libextract是一个statistics-enabled 数据提取库,用于处理HTML和XML文档并用 Python。源于eatiht, 提取算法通过一个简单的假设工作:数据显示为 重复元素的集合。你可以读到推理 here。
概述
- libextract.api.extract(文档,编码为utf-8,计数为5)
- 给定一个htmldocument,并可选地返回encoding。 可能包含数据的节点列表(默认为5个)。
安装
pip install libextract
用法
由于我们对“数据”的简单定义,我们打开了一个 接口方法。后期处理由您决定。
fromrequestsimportgetfromlibextract.apiimportextractr=get('http://en.wikipedia.org/wiki/Information_extraction')textnodes=list(extract(r.content))
使用lxml的内置方法进行后处理:
>>print(textnodes[0].text_content())Informationextraction(IE)isthetaskofautomaticallyextractingstructuredinformation...
提取算法对文章文本是不可知的 表格数据:
height_data=get("http://en.wikipedia.org/wiki/Human_height")tabs=list(extract(height_data.content))
>>[elem.text_content()forelemintabs[0].iter('th')]['Country/Region','Average male height','Average female height',...]
依赖性
lxml statscounter
免责声明
该项目仍处于起步阶段,建议如下 我们将非常感谢这个图书馆能够和应该做些什么
:)