【发布时间】:2019-12-23 14:46:30
【问题描述】:
我使用 pandas 解析它:
s = '<table id="datatable"><tr><th onclick="sortTable(0)">Gene locus</th><th onclick="sortTable(1)">Organism</th><th onclick="sortTable(2)">Found in</th><th onclick="sortTable(3)">Gene name</th><th onclick="sortTable(4)">AA mutation</th><th onclick="sortTable(5)">Drug</th><th onclick="sortTable(6)">Tandem repeat name</th><th onclick="sortTable(7)">Tandem repeat sequence</th><th onclick="sortTable(8)">Reference</th></tr><td>ASPNIDRAFT_55947</td><td>Aspergillus niger</td><td>Animal - Human</td><td>CYP51a</td><td>R228Q </td><td>Posaconazole</td><td></td><td><div style="word-wrap: break-word;max-width: 250px;"></div></td><td><a href="http://jcm.asm.org/content/54/9/2365.full">10.1128/JCM.01075-16</a></td></tr></table>'
table = pandas.read_html(s)[0]
print(table)
但是这给了我:
Empty DataFrame
Columns: [Gene locus, Organism, Found in, Gene name, AA mutation, Drug, Tandem repeat name, Tandem repeat sequence, Reference]
Index: []
在标题 (<th>..) 下方显然有一个实心行 (<tr>...),所以我不知道哪里出了问题,更重要的是我无法正确阅读表格。
(P.s. 我现在无法从我所在的国家/地区访问 Imgur,所以如果链接不合适,请随时更改它或告诉我如何更改它)
【问题讨论】:
标签: python html pandas html-table html-parsing