0

Python スクリプトを使用して編集したい HTML ページがあります。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 には「頭」があります。

dominate を使用してファイルを編集するにはどうすればよいですか?

4

1 に答える 1