我试图使用pandasread_html
函数来阅读位于here的“众议院正式名单”。在
使用
df_list = pd.read_html('http://clerk.house.gov/member_info/olmbr.aspx',header=0,encoding = "UTF-8")
house = df_list[0]
我确实得到了一个很好的数据框,上面有代表的姓名、州和地区。标题正确,编码也正确。到现在为止,一直都还不错。在
然而,问题在于党。聚会没有专栏。相反,该方用字体(罗马或斜体)表示。查看HTML源代码,下面是一个民主党人的条目:
^{pr2}$这里有一个共和党人的条目:
<tr><td>Anderholt, Robert B.</td><td>AL</td><td>4th</td></tr>
共和党人的名字周围缺少<em></em>
标签。在
如何检索这些信息?可以用pandas完成吗?还是需要一些更复杂的HTML解析器?如果是,那是哪一个?在
我认为您需要创建解析器:
^{pr2}$
也可以为所有可能的标记创建带有
1
和0
的列:相关问题 更多 >
编程相关推荐