gpt4 book ai didi

python - 使用 Python Dominate 库将 <style> 元素添加到 HTML

转载 作者:行者123 更新时间:2023-12-01 01:19:23 25 4
gpt4 key购买 nike

我正在尝试使用Python 中的主导包生成HTML。对于格式,我必须在<style>中添加一个简短的CSS内容。标签。但是,我能找到的唯一文档是 GitHub 页面,该页面没有任何与添加 <style> 相关的功能。 .

PS:这是一张图片

enter image description here

最佳答案

这就是你所追求的吗? from here

import dominate
from dominate.tags import link, script, style

doc = dominate.document(title='Dominate your HTML')

with doc.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
style("""\
body {
background-color: #F9F8F1;
color: #2C232A;
font-family: sans-serif;
font-size: 2.6em;
margin: 3em 1em;
}

""")

print(doc.render(pretty=True))

它产生;

<!DOCTYPE html>
<html>
<head>
<title>Dominate your HTML</title>
<link href="style.css" rel="stylesheet">
<script src="script.js" type="text/javascript"></script>
<style> body {
background-color: #F9F8F1;
color: #2C232A;
font-family: sans-serif;
font-size: 2.6em;
margin: 3em 1em;
}

</style>
</head>
<body></body>
</html>

关于python - 使用 Python Dominate 库将 &lt;style&gt; 元素添加到 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53992303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com