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
相关推荐
froginwe11几秒前
Maven 仓库概述
开发语言
我不是QI8 分钟前
周志华《机器学习---西瓜书》 一
人工智能·python·机器学习·ai
今天没ID9 分钟前
Python 编程实战:从基础语法到算法实现 (1)
python
二川bro33 分钟前
Python在AI领域应用全景:2025趋势与案例
开发语言·人工智能·python
棒棒的皮皮1 小时前
【Python】Open3d用于3D测高项目
python·3d·open3d
CoderYanger1 小时前
优选算法-队列+宽搜(BFS):72.二叉树的最大宽度
java·开发语言·算法·leetcode·职场和发展·宽度优先·1024程序员节
CodeLongBear1 小时前
Python数据分析: 数据可视化入门:Matplotlib基础操作与多坐标系实战
python·信息可视化·数据分析
疏狂难除1 小时前
随便玩玩lldb (二)
开发语言·后端·rust
星轨初途1 小时前
数据结构排序算法详解(5)——非比较函数:计数排序(鸽巢原理)及排序算法复杂度和稳定性分析
c语言·开发语言·数据结构·经验分享·笔记·算法·排序算法
b***65321 小时前
GO 快速升级Go版本
开发语言·redis·golang