我有一个 HTML 页面,我想使用 python 脚本对其进行编辑。我正在使用Dominate库
这是一个准系统示例。
<html>
<head>
<title>asdjasda</title>
</head>
<body>
<h1>THIS IS A TEST</h1>
</body>
</html>
简单的 HTML 对吗?
这是python脚本:
import dominate
from dominate.tags import *
page = open('index.html','r',encoding='utf-8')
with page.head:
link(rel='stylesheet', href='tts.css')
page.close()
运行此脚本时出现以下错误。
Traceback (most recent call last):
File "script.py", line 6, in <module>
with page.head:
AttributeError: '_io.TextIOWrapper' object has no attribute 'head'
我的 HTML 确实有一个“头”。
如何使用主宰来编辑我的文件?