lok*_*art 8 html python import pandas
作为标题,我尝试使用read_html但给我以下错误:
In [17]:temp = pd.read_html('C:/age0.html',flavor='lxml')
File "<string>", line unknown
XMLSyntaxError: htmlParseStartTag: misplaced <html> tag, line 65, column 6
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
HTML 在顶部包含一些 javascript,然后是一个 html 表。我使用 R 来处理它,通过 XML 包解析 html 给我一个数据框。我想用 python 来做,我应该在给熊猫之前使用像 beautifulsoup 这样的其他东西吗?
我认为您通过使用像漂亮汤这样的 html 解析器走上了正确的轨道。pandas.read_html() 读取 html 表而不是 html 页面。
你会想做这样的事情......
from bs4 import BeautifulSoup
import pandas as pd
table = BeautifulSoup(open('C:/age0.html','r').read()).find('table')
df = pd.read_html(table) #I think it accepts BeatifulSoup object
#otherwise try str(table) as input
Run Code Online (Sandbox Code Playgroud)