由python获取的数据,可以通过保存到html中展示,借助css样式,实现更加直观好看的效果。
1. html模板
2.数据替换
html = """<!DOCTYPE html>
<html lang="en">
<head>title</head>
<body>
<table border='1'>
<thead>
<tr>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>%s</tr>
</tbody>
</body>
</html>"""
tr = "Just for test"
f = open('temp.html','w')
f.write(html%tr)
f.close()
从list中读取数据并填充到html 変量中
html = """<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"></head>
<body>
<table border='1'>
<thead>
<tr>
<th>Date</th>
</tr>
</thead>
<tr>
<th></th>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>d</th>
</tr>
<tr>
<td>F </td>
<td>%s件</td>
<td>%d件</td>
<td>%d</td>
<td>%s件</td>
<td>%d件</td>
</tr>
</body>
</html>"""
datas = ['Table ', 14, 14, '一致', 14]
f = open('temp.html','w',encoding="utf-8")
f.write(html%(tuple(datas)))
f.close()
缺点:只能按照顺序, 且html固定,也不是太灵活
更多推荐
python将数据结果保存到html文件中展示
发布评论