gpt4 book ai didi

python - 如何在终端中以 'page' 打印带有 html 内容的 python 变量?

转载 作者:行者123 更新时间:2023-11-27 22:45:00 25 4
gpt4 key购买 nike

我有一个带有 html 内容的 python 变量

>>>>a='<html><h1><a href="http://www.google.com">Link to Google<></h1></html>'

如何将其打印为 html?

我想在我的终端中打印这个变量,我想要这样的结果:

a.html

OBS.: 如果 python 可以在没有 shell 脚本或其他程序的情况下做到这一点,我会更喜欢这个。

最佳答案

我成功地做了一个 python 程序 a.py 如下:

a='<html><h1>My example text</h1></html>'
file=open("a.html","w")
file.write(a+'\n')
file.close

然后执行另一个 shell 脚本 a.sh,例如:

#!/bin/sh
/usr/bin/env python a.py
w3m a.html

但是我觉得不是什么好办法,不是只有python的吗?

关于python - 如何在终端中以 'page' 打印带有 html 内容的 python 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8074448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com