python 文本转html

在 Python 中,可以使用三方库 BeautifulSoup 将文本转换为 HTML。

首先,安装 BeautifulSoup 库:

pip install beautifulsoup4

然后,创建一个简单的 Python 脚本,使用 BeautifulSoup 将文本转换为 HTML:

from bs4 import BeautifulSoup
text = "This is some text."
soup = BeautifulSoup(text, 'html.parser')
html = soup.prettify()
print(html)

运行此代码将生成以下输出:

This is some text. </body> </html>
  •