pyecharts生成的文件标题如何修改

明明在代码里写明了标题:

chart2 = Bar() 
chart2.add_xaxis(daocha_total) 
chart2.add_yaxis('道岔检查完成度', daocha_barvalue) 
chart2.set_global_opts(
    title_opts=opts.TitleOpts(title="道岔检查完成度"),
    yaxis_opts=opts.AxisOpts(
        axislabel_opts=opts.LabelOpts(
            formatter="{value}%"
        )
    )
)
chart2.render(r"Task-progress-visualization-main\newfile\standingSystem\html\道岔检查完成度.html")

但是浏览器打开后,html文件还是显示Awesome-pyecharts

img

利用beautifulsoup库,重写文件标题


import soupsieve
from bs4 import BeautifulSoup 

# 读取 HTML 文件
with open(r"Task-progress-visualization-main\newfile\standingSystem\html\道岔检查完成度.html", 'r', encoding='utf-8') as f:
    html = f.read()

# 使用 BeautifulSoup 解析 HTML
soup = BeautifulSoup(html, 'html.parser')

# 找到 title 标签,并修改其文本内容
title_tag = soup.find('title')
title_tag.string = "道岔检查完成度"

# 将修改后的 HTML 内容写入文件
with open('example.html', 'w', encoding='utf-8') as f:
    f.write(str(soup))

要不换个浏览器刷新缓存试一下?