简单的HTML表提取器。
html2dict的Python项目详细描述
警告:此脚本尚未准备好供生产使用。
*尚未分析所有表。请参阅"功能"部分以获取支持的表类型列表。*
>简单的html表提取程序。
\prerequisite
*python 3.6+
*python模块:
*[lxml](https://lxml.de/)
*[请求](http://docs.python-requests.org/en/master/)
没有标题。
*带表头的基本表。
*带合并表头的复杂表。
表类型列表**当前不受**支持:
*任何嵌入iframes的表。
*带垂直表头的表(scope="col")
*第一组数据后有新表头行的表。
*合并表的表跨越多个级别
此项目仍然很新,如果要分析的表类型不在此列表中,请让我知道结果。
(目前只有一个可用)。
``python
from html2dict.extractors导入basictableextractor
```
>然后使用提供的3个构造函数之一实例化一个对象=basictableextractor.from_html_file(html_file=<;relative_或_absolute_filepath>;)
或
my_extractor=basictableextractor.from_url(url=<;url>;)
`````
bles
```
最后,可以从属性数据行或行访问表的数据。
``python
``myu extractor.basic_tables[<;table_name>;].rows
````
`examples
*for https://www.python.org/downloads/release/python-370/
``python
my_extractor=basictableextractor.from_url(url="https://www.python.org/downloads/release/python-370/")
my_extractor.basic_tables
{'table_0':<;html2dict.table object at 0x10700c828>;}
pprint(my_extractor.basic_tables['table_0'].rows)
{'data':[{'description':'N/A',
'文件大小':'22745726',
'GPG':'SIG',
'MD5 SUM':'41B6595DEB4147A1ED517A7D9A580271',
'操作系统':'SOURCE RELEASE',
'版本':'GZIPPED SOURCE tarball',
{'说明':'N/A',
'FIle size':'16922100',
'gpg':'sig',
'md5 sum':'eb8c2a6b1447d50813c02714af4681f3',
'operating system':'source release',
'version':'xz compressed source tarball'},
{'description':'适用于Mac OS X 10.6及更高版本,
'文件大小':'34274481',
'gpg':'sig',
'md5 sum':'ca3eb84092d0ff6d02e42f63a73438e',
'操作系统':'mac os x',
'版本':'macos 64位/32位安装程序'},
{'说明':'os x 10.9及更高版本,
'f文件大小':'27651276',
'gpg':'sig',
'md5 sum':'ae0717a02efea3b0eb34aadc680dc498',
'操作系统':'mac os x',
'版本':'macos 64位安装程序'},
{'说明':'n/a',
'文件大小':'8547689',
'gpg':'sig',
'md5 sum':'46562af86c249dd0cc7680348180dca',
'操作系统':'windows',
'版本':'windows帮助文件'},
{'说明':'amd64/em64t/x64',
'文件大小':'6946082',
'gpg':'sig',
'md5 sum':'cb8b4f0d979a36258f73ed541def10a5',
'操作系统':'windows',
'版本':'windows x86-64可嵌入zip文件'},
{'说明':'amd64/em64t/x64',
'文件大小':'26262280',
'gpg':'sig',
'md5 sum':'531c3fc821ce0a4107b6d2c6a129be3e',
'operating system':'windows',
'version':'windows x86-64可执行安装程序'},
{'description':'for amd64/em64t/x64',
'file size':'1327160',
'gpg':'sig',
'md5 sum':'3cfdaf4c8d3b0475aaec12ba402d04d2',
'operating system':'windows',
'version':'windows x86-64 web-based installer'},
{'description':'n/a',
'file size':'6395982',
'gpg':'sig',
'MD5 sum':'ed9a1C028c1e99f53232b9c20723d7d6f',
'操作系统':'windows',
'版本':'windows x86可嵌入zip文件'},
{'说明':'n/a',
'文件大小':'25506832',
'gpg':'sig',
'MD5 sum':'ebb6444c284c'1447E902E87381AFFF0',
"操作系统":"Windows",
"版本":"Windows x86可执行安装程序"},
{"说明":"N/A",
"文件大小":"1298280",
"GPG":"SIG",
"MD5总和":"779C4085464EB3EE5B1A4 FFFD0EABCA4"
‘操作系统’:‘windows’,
‘版本’:‘windows x86基于web的安装程序’},
‘标题’:[[‘版本’,
‘操作系统’,
‘说明’,
‘md5和’,
‘文件大小’,
‘gpg’]}
```