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
相关推荐
码农黛兮_4620 分钟前
4. 文字效果/2D-3D转换 - 3D翻转卡片
3d·html·css3
belldeep2 小时前
如何阅读、学习 Tcc (Tiny C Compiler) 源代码?如何解析 Tcc 源代码?
c语言·开发语言
LuckyTHP2 小时前
java 使用zxing生成条形码(可自定义文字位置、边框样式)
java·开发语言·python
mahuifa3 小时前
(7)python开发经验
python·qt·pyside6·开发经验
小嘟嚷ovo4 小时前
h5,原生html,echarts关系网实现
前端·html·echarts
学地理的小胖砸5 小时前
【Python 操作 MySQL 数据库】
数据库·python·mysql
安迪小宝5 小时前
6 任务路由与负载均衡
运维·python·celery
Blossom.1185 小时前
使用Python实现简单的人工智能聊天机器人
开发语言·人工智能·python·低代码·数据挖掘·机器人·云计算
da-peng-song5 小时前
ArcGIS Desktop使用入门(二)常用工具条——数据框工具(旋转视图)
开发语言·javascript·arcgis
galaxy_strive5 小时前
qtc++ qdebug日志生成
开发语言·c++·qt