Python提供了多种库可以用来显示HTML文档,其中比较常用的是webbrowser和IPython.display模块。
使用webbrowser模块打开HTML文件:
import webbrowser
webbrowser.open('example.html')
使用IPython.display模块在Jupyter Notebook或IPython环境中显示HTML文档:
from IPython.display import HTML
with open('example.html', 'r') as f:
html_content = f.read()
HTML(html_content)