python 生成html文件并端口展示

1.生成相关的html文件

python 复制代码
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 = '<html>\n<html lang="zh">\n<head>\n<meta charset="UTF-8">\n<title>图片展示</title>\n</head>\n<body>\n'
for line in lines:
    line_vec = line.strip().split("\t")
    html += '<div>\n'
    if len(line_vec)>2:
        for i in range(2,len(line_vec)):
            html += '<img src="'+line_vec[i]+'" width="400">\n'
    html += '<p>query is: {'+line_vec[0]+'}</p>\n'
    html += '<p>tags are: {'+line_vec[1]+'}</p>\n'
    html += '</div>\n'
html += '</body>\n</html>'
 
# 写入HTML文件
with open('result.html', 'w') as f:
    f.write(html)

2.终端执行

bash 复制代码
python3 -m http.server 8080

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

bash 复制代码
http://127.0.0.1:8080/result.html
相关推荐
跟橙姐学代码24 分钟前
Python异常处理:告别程序崩溃,让代码更优雅!
前端·python·ipython
蓝纹绿茶44 分钟前
Python程序使用了Ffmpeg,结束程序后,文件夹中仍然生成音频、视频文件
python·ubuntu·ffmpeg·音视频
mahuifa1 小时前
OpenCV 开发 -- 图像基本处理
人工智能·python·opencv·计算机视觉
土了个豆子的1 小时前
03.缓存池
开发语言·前端·缓存·visualstudio·c#
_extraordinary_1 小时前
Java 多线程(一)
java·开发语言
爱喝水的鱼丶1 小时前
SAP-ABAP: ABAP ASSIGN COMPONENT 语句详解:动态字段符号的利器作用用法示例详解
运维·开发语言·sap·abap·开发经验·动态字段符号
一个java开发1 小时前
distributed.client.Client 用户可调用函数分析
大数据·python
励志不掉头发的内向程序员1 小时前
C++进阶——多态
开发语言·c++·学习
eqwaak02 小时前
Matplotlib 动态显示详解:技术深度与创新思考
网络·python·网络协议·tcp/ip·语言模型·matplotlib
007php0072 小时前
某大厂MySQL面试之SQL注入触点发现与SQLMap测试
数据库·python·sql·mysql·面试·职场和发展·golang