Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中使用可点击的html链接作为列的PrettyTable_Python_Hyperlink_Prettytable - Fatal编程技术网

在python中使用可点击的html链接作为列的PrettyTable

在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

我正在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\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))