【问题标题】:Add HTML paragraph to the beginning of Dominate Document将 HTML 段落添加到 Dominate Document 的开头
【发布时间】:2022-08-16 10:18:50
【问题描述】:

来自支配 github:

文档类还提供了帮助器,允许您直接将节点添加到 body 标记。

d = document()
d += h1(\'Hello, World!\')
d += p(\'This is a paragraph.\')
print(d)


<!DOCTYPE html>
<html>
    <head>
       <title>Dominate</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
        <p>This is a paragraph.</p>
    </body>
</html>

如何在现有段落之前添加段落?

我试过了:

d = p(\"Offer Ends Soon\") + d

收到此错误 错误:类型错误 + 不支持的操作数类型:\'p\' 和 \'document\'

我试过了:

d += p(\"Offer Ends Soon\")

但这会将新段落放在底部,而不是顶部

<!DOCTYPE html>
<html>
    <head>
       <title>Dominate</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
        <p>This is a paragraph.</p>
        <p>Offer Ends Soon</p>
    </body>
</html>
  • 我认为您不能使用 Dominate 将标签添加到 document() 中。 document() 在修改方面非常不可延展,仅用于快速原型制作。您可能只需要在 GitHub 存储库中为该库提交功能请求。
  • 从 cmets 开始:stackoverflow.com/q/45659712/5281962。 \"Dominate 不是 HTML 解析器。它只用于创建新文档,而不是解析现有的 html 文件。\"

标签: dominate


【解决方案1】:

这是不可能的。您不能使用 document() 预先添加标签。

来自here

Dominate 不是 HTML 解析器。它严格用于创建新文档,而不是解析现有的 html 文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-12
    • 2016-01-19
    • 1970-01-01
    • 2013-05-16
    • 2020-08-14
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    相关资源
    最近更新 更多