从html表中提取数据的python库

html-table-extractor的Python项目详细描述


#HTML表格提取器
[![构建状态](https://travis-ci.org/yuanxu-li/html-table-extractor.svg?branch=master)(https://travis ci.org/yuanxu li/html table extractor)


网站/yunxu-li/html表抽取器
*问题:http://github.com/yunxli/html表抽取器/issues





`` bash
pip install'beautifulsoup4==4.5.3'
pip install html表抽取器
``
`
`
`



//

<;表>;lt;lt;tr>;lt;td>;lt;lt;td>;lt;lt;td>;2<;lt;lt;lt;lt;lt;lt;lt;tr>;lt;gt;lt;lt;td>;gt;lt;lt;lt;td>;3<;lt;lt;lt;td>;lt;gt;lt;lt;lt;td>;4<;lt;lt;lt;lt;lt;lt;lt;tr>;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;"tr">lt;"td">1>;lt;lt;td>;2<;lt;td>;lt;td>;lt;lt;td>;3<;lt;td>;lt;lt;td>;4<;lt;lt;td>;lt;lt;lt;lt;tr>;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;表>;
"
提取器=提取器(表文档)
提取器.parse()
提取器.return a list()
`>``>br/>它将打印出来:
>``python
>>>[[u'1'u'1'u'u'1'u'u'1'u'u'u 2'],[U'3',U'4']
```





<;lt;tr>;<;lt;td>;1<;lt;lt;td>;lt;lt;lt;td>;gt;lt;lt;td>;lt;gt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;gt;lt;gt;lt;lt;gt;lt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;gt;lt;lt;gt;gt;3<;lt;lt;lt;lt;lt;td>;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;u提取器。提取器导入提取器
表格
<;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;lt;lt``
它将打印输出:
```python
[[1,2],[3,4]]
````





\35353535353535353535;;;;;>;<;/tr>;<;/table>;

``来自html表的python
_extractor.extractor import extractor
来自BS4 import beautifulsoup
table\u doc="
<;html>;<;table id='wanted'>;<;tr>;<;td>;1<;/td>;<;td>;2<;/td>;<;/tr>;<;tr>;<;td>;3<;/td>;<;td>;4<;<;/td>;<;&tr>;<;<;table>;<;table id='unwanted'>;<;tr>;<;td>;不需要<;/td>;<;/tr>;<;/table>;<;/html>;
"
soup=beautifulsoup(table_doc,'html.parser')
extractor=extractor(soup,id_wanted')
extractor.parse()
extractor.return_list()
`````
```python
[[u'1',u'2",[U'3',U'4']]
``````






<;table>;
<;tr>;
<;lt;tr>;
<;td rowsspan=2>;1<;lt;td>;
<;td>;2<;lt;td>;2<;lt;td>;
><;lt;td>;3<;lt;lt;td>;lt;lt;lt;lt;lt;td>;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt<;tr>;
<;td colspan=2>;4<;/td>;
<;br/><;lt;br/><;lt;br/><;lt;lt;td colspan=3>;5<;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;br/><;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt>;
<;lt;lt;td>;2<;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt"
提取器=提取器(表格文件)
extractor.parse()
tractor.return_list()
`````
它将打印输出:
```python
[[u'1',u'2',u'3'],[u'1',u'4',u'4'],[u'5',u'5',u'5']]
`````



```>

;示例5-冲突


>
><;tr gt<;tr
<;td rowspan=2>;1<;td>;
<;lt;lt;td>;2<;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt br/>
``巨蟒
from html_table_extractor.extractor import extractor
table_doc="
<;table>;
<;tr>;
<;td rowspan=2>;1<;td>;
<;td>;2<;td>;
<;td rowspan=3>;3<;td>;
<;tr>;
<;tr>;
<;tr>;
<;td colspan=2>;4<;lt;lt;td>;
<;lt;br/><;lt;tr>;
<;td colspan=2>;5<;lt;td>;
<;lt;br/><;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;br/>extrator=extrator(table_doc)
extrator=extrator(table_doc)
extrator.parse()
>extrator.retrator.returnu list()
`>>````>br/>;它会打印出来:它会打印出来:它会打印出来:[U'1',U'2',U'3'],[U'1','U'4','U'3'],[U'5','U'5','U'5','U'3']]
`````




>第六例-写入文件


<;表>;lt;tr>;lt;tr>;lt;td>;1<;lt;td>;lt;lt;td>;lt;lt;td>;2<;lt;lt;lt;td>;lt;lt;lt;tr>;lt;lt;tr>;lt;lt;gt;lt;gt;lt;gt;lt;lt;gt;gt;lt;lt;lt>;4<;td>;<;tr>;<;table>;

``python
来自html表_提取器-提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-提取器-进口提取器-进口提取器-进口提取器-进口提取器-lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt U CSV公司(path='.')
```
它将写入给定的路径,并创建一个名为output.csv的新cscsv文件:
````
>1,2
>3,4


````
`
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `或者如果你有关于改进的建议,[请在此处报告](https://github.com/yuanxu li/table extractor/issues)


\copyright

copyright(c)2017 justin li。根据[麻省理工学院许可证](https://github.com/yuanxu li/html table extractor/blob/master/readme.md)发布


本发行版中的第三方版权在适用的情况下注明。



欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为扫描器的输入生成字符序列   hibernate中的java实体合并   如何使变量在Java文件中成为全局变量   java JVM崩溃“异常访问冲突”   向MediaMetadataRetriever中的setDataSource()发送Uri时发生java IllegalArgumentException   java没有节约协议?   用户界面java gui帮助actionlistener   java索引越界异常,即使大小小于索引?   在C++中使用java的困惑   在普通java编码中插入图像   JDBC上的java缓存数据   在Java中,在字符串的特定位置替换子字符串   java在运行elasticsearch集群时遇到Perm Gen空间问题   java Soap故障跟踪   java拆分器。固定长度(int)。拆分(字符串)   java获取jar内部包的路径