【发布时间】:2021-06-29 00:45:27
【问题描述】:
我正在从 API 中抓取数据并使用 html_file.write 方法将它们输入到 html 文件中。我想将文本居中并添加边框和字体等。但是当我将例如 .content 类添加到
html_content=f"<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>"+"""
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Questrial&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<style>
.content {
width: 50%;
margin: auto;
background: white;
padding: 10px;
}
img{
max-width: 100%;
}
body {background-color: LightGray;}
h1 {color: red;}
h2 {color: red;}
</style>
"""+f"</head><body><div class="container"><h1><h1><font size='6'><strong>{Q}</strong></font></h1><p>{content2modified}</p><hr><h1><font size='6'><strong>{A}</strong></font></h1><p>{contentmodified}</p> </body></div> </html>"
with open("index.html","w",encoding='utf-8') as html_file:
html_file.write(html_content)
print("Success")
await message.author.send(file=discord.File('index.html'))
【问题讨论】:
标签: python html api discord.py