在 Python 中可以使用第三方库如 BeautifulSoup 来创建 HTML 文件。
示例代码如下:
frombs4 import BeautifulSoup
# 创建 HTML 文件
soup = BeautifulSoup("<html></html>", "html.parser")
# 在 <html> 标签中添加 <body> 标签
body = soup.new_tag("body")
body["style"] = "background-color: black; color: white;"
soup.html.append(body)