1
我試圖更改以下HTML文檔中標題的值:LXML:元素不是此節點的子
<html lang="en">
<head>
<meta charset="utf-8">
<title id="title"></title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
我寫了使用LXML,爲了下面的Python腳本來完成任務:
from lxml.html import fromstring, tostring
from lxml.html import builder as E
html = fromstring(open('./index.html').read())
html.replace(html.get_element_by_id('title'), E.TITLE('TEST'))
但運行該腳本後,我收到以下錯誤:
ValueError: Element is not a child of this node.
什麼應該會導致這個錯誤?謝謝。
''