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
相关推荐
ponponon25 分钟前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly26 分钟前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程39 分钟前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly3 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
明月_清风9 小时前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风9 小时前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
anOnion18 小时前
构建无障碍组件之Switch Pattern
前端·html·交互设计
ZhengEnCi1 天前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风1 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风1 天前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python