首页 > 解决方案 > Python,将html表转换为数据框

问题描述

我正在尝试使用 parser.make2d 函数将我的 html 表转换为可用的数据框,但我无法安装 parser.make2d 的模块。在我的 python 2.7 中,它找不到“html_table_parser”模块,因此“from html_table_parser import parser_functions as parse”不起作用。

from urllib2 import urlopen
import pandas as pd
from bs4 import BeautifulSoup
import webbrowser
import requests
from html_table_parser import parser_functions as parse

report = requests.get(url_parsing, proxies = proxies)
report2 = BeautifulSoup(report.text,'html.parser')
body=report2.find("body")
table=body.find_all("table")
p = parser.make2d(table[3])

标签: pythondataframebeautifulsouphtml-parsing

解决方案


似乎没有安装 html_table_parser 模块。

你试过跑步吗

python -m pip install html_table_parser

在命令行上?


推荐阅读