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
相关推荐
像是套了虚弱散6 小时前
DevEco Studio与Web联合开发:打造鸿蒙混合应用的全景指南
开发语言·前端·华为·harmonyos·鸿蒙
旭意7 小时前
C++蓝桥杯之结构体10.15
开发语言·c++
飞翔的佩奇7 小时前
【完整源码+数据集+部署教程】【天线&水】舰船战舰检测与分类图像分割系统源码&数据集全套:改进yolo11-repvit
前端·python·yolo·计算机视觉·数据集·yolo11·舰船战舰检测与分类图像分割系统
麦麦鸡腿堡8 小时前
Java的单例设计模式-饿汉式
java·开发语言·设计模式
简单点了8 小时前
go前后端项目的启动 、打包和部署
开发语言·后端·golang
木头左8 小时前
最大回撤约束下ETF多因子动态止盈参数校准方案
python
爱吃山竹的大肚肚8 小时前
@Valid校验 -(Spring 默认不支持直接校验 List<@Valid Entity>,需用包装类或手动校验。)
java·开发语言
汤姆yu8 小时前
2026版基于python的协同过滤音乐推荐系统
开发语言·python
程序猿追8 小时前
Vue组件化开发
前端·html
汤姆yu8 小时前
基于python的电子商务管理系统
开发语言·python