python 生成html文件并端口展示

1.生成相关的html文件

import json
import os
import calc
import requests
import numpy as np
 
with open('picture', 'r',encoding='utf-8') as f:
    lines = f.readlines()
html = '\n\n\n\n图片展示\n\n\n'
for line in lines:
    line_vec = line.strip().split("\t")
    html += '
\n' if len(line_vec)>2: for i in range(2,len(line_vec)): html += '+line_vec[i]+'" width="400">\n' html += '

query is: {'+line_vec[0]+'}

\n'
html += '

tags are: {'+line_vec[1]+'}

\n'
html += '
\n'
html += '\n' # 写入HTML文件 with open('result.html', 'w') as f: f.write(html)

2.终端执行

python3 -m http.server 8080

3.浏览器访问ip+端口号进行查看(改成自己当前机器的ip)

http://127.0.0.1:8080/result.html

你可能感兴趣的:(python,html,开发语言)