【发布时间】:2019-08-12 18:58:49
【问题描述】:
我目前正在使用beautifulsoup 在网站上抓取表格,该表格包含链接,然后我将此表格转换为pandas 数据框并使用pandas 'to_html' 选项将其转换为html,这一切都在Django 中运行.
这就是我在 Python 中创建表格的方式:
res = []
for row in table.find_all('tr'):
row_data = []
for td in row.find_all('td'):
td_check = td.find('a')
if td_check is not None:
link = td.find('a')
row_data.append(link)
else:
not_link = ''.join(td.stripped_strings)
if not_link == '':
not_link = None
row_data.append(not_link)
res.append(row_data)
然后我使用以下代码将其转换为 HTML:
sangerDF = sangerDF.to_html(classes=["table-bordered", "table-striped", "table-hover",], index=False, justify="initial")
但它会像这样在我的网站上输出表格:
我不明白为什么它不可点击?如果我使用浏览器检查表格中的单元格,则 HTML 为:
<td>
<a href="https://www.sanger.ac.uk/htgt/wge/crispr/1006029202">1006029202</a>
</td>
所以某处的格式出现问题,我该如何解决?
谢谢!
【问题讨论】:
标签: python django pandas html-table hyperlink