用python库从具有rowspan的html表中提取数据
py-html-table的Python项目详细描述
PY HTML表格包
这是一个简单的包,它使用beautifulsoup来提取具有rowspan的html表数据。
安装
pip install py html表
声明
将py_html_table.py_html_table导入为pyht
参数
Parameter | Meaning | Sample Values |
---|---|---|
table | python variable containing html code of table | any variable name |
begin | No.of rows to begin scrapping. Starts from 0 | 2 |
col | Total No.of columns in the table. Starts from 1 | 5 |
output | Type of output that you need | list (or) dataframe (or) csv |
raw | 'Y' to get exact content inside table cell. 'N' to get only text | 'Y' or 'N' |
注意:所有变量名必须作为包的输入提供
用法示例
导入请求
从bs4导入beautifulsoup
导入请求
将lxml.html导入为lh
将py_html_table.py_html_table导入为pyht
url='https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States'
session=请求html.htmlsession()
r=session.get(url)
content=美化组(r.content,“lxml”)
所有表=内容。选择(“.wikitable”)
table=所有表[0]
col=9
开始=2
输出=“数据帧”
原始='n'
pyht.extract(表、开始、列、输出、原始)