我想构建一个简单的 http 服务器,它接收文本字符串列表并发送简单的动态 html 页面,循环显示它们(类似于 RSS) 它工作正常,但现在我想控制文本属性 如何更改文本属性,例如将背景更改为透明、文本大小和字体? 该页面是使用 python HTTPserver 模块构建的 它发送单个简单的 html 页面作为对 GET 请求的响应,我不确定如何在脚本中嵌入 css 或其他技巧
下面的python函数接收包含以逗号分隔的字符串列表(文本)的字符串,将其作为数组嵌入到html脚本中(用文本替换文本)并将其作为html正文的一部分发送到响应中
def write_response(self, text):
print(content)
self.send_response(200)
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()
f = open('html.txt', "r")
html = f.read()
body = html.replace('TEXT', text)
print(body)
self.wfile.write(body.encode(encoding='utf-8'))
html.txt 文件
<script>
var example = [TEXT];
textSequence(0);
function textSequence(i) {
if (example.length > i) {
setTimeout(function() {
document.getElementById("sequence").innerHTML = example[i];
textSequence(++i);
}, 1000); // 1 second (in milliseconds)
} else if (example.length == i) { // Loop
textSequence(0);
}
}
</script>
<div id="sequence"></div>