在python中使用可点击的html链接作为列的PrettyTable
我正在python中使用pretty table创建一个表,并尝试创建一个列,其中URL包含可单击的链接: 例如:在python中使用可点击的html链接作为列的PrettyTable,python,hyperlink,prettytable,Python,Hyperlink,Prettytable,我正在python中使用pretty table创建一个表,并尝试创建一个列,其中URL包含可单击的链接: 例如: filepath=“pretty\u table.html” 从prettytable导入prettytable x=PrettyTable() x、 格式=真 x=PrettyTable([“城市名称”、“区域”、“Url”]) x、 添加_行([“阿德莱德”,1295,“]) x、 添加_行([“布里斯班”,5905,“])) 结果=[] result.append(x.get
filepath=“pretty\u table.html”
从prettytable导入prettytable
x=PrettyTable()
x、 格式=真
x=PrettyTable([“城市名称”、“区域”、“Url”])
x、 添加_行([“阿德莱德”,1295,“])
x、 添加_行([“布里斯班”,5905,“]))
结果=[]
result.append(x.get\u html\u string())
将open(filepath,'w')作为f:
对于行输入结果:
f、 写入(“{}\n”。格式(行))
但是,使用上述方法,该表不会为wiki页面生成可单击的链接。有人能帮忙吗 答案就在这里
导入html
url='1〕https://www.baidu.com“#链接到指向
增加第二行(['2018-10-10','')
text=pt.get\u html\u字符串(格式=True)
text=html.unescape(text)#关键步骤
可以找到更多信息
filepath = "pretty_table.html"
from prettytable import PrettyTable
x = PrettyTable()
x.format = True
x = PrettyTable(["City name", "Area", "Url"])
x.add_row(["Adelaide",1295, "<a href='https://en.wikipedia.org/wiki/Adelaide'>https://en.wikipedia.org/wiki/Adelaide</a>" ])
x.add_row(["Brisbane",5905, "<a href='https://en.wikipedia.org/wiki/Brisbane'>https://en.wikipedia.org/wiki/Brisbane</a>"])
result = []
result.append(x.get_html_string())
with open(filepath, 'w') as f:
for line in result:
f.write("{}\n".format(line))