如何使用Python在同一窗口中打开不同的html文件

2024-06-16 10:55:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个名为'Doc'的文件夹,Doc文件夹包含一些子文件夹,每个文件夹都有'.html'文件。我必须使用Python代码在webbreowser中随时打开。我打开了它,但问题是,html文件不是在同一个窗口中打开的。有时每个文件都会在新窗口中打开。我不知道确切的问题是什么。这是我试过的密码

import os  
import webbrowser

for root, dirs, files in os.walk("Doc"):

    for file in files:

        if file.endswith("index.html"):                    
            webbrowser.open_new_tab(os.path.join(root, file))

Tags: 文件代码inimport文件夹密码fordoc
1条回答
网友
1楼 · 发布于 2024-06-16 10:55:39

RTFM(https://docs.python.org/2/library/webbrowser.html

webbrowser.open_new_tab(url) Open url in a new page (“tab”) of the default browser, if possible, otherwise equivalent to open_new().

这只是一个最大的努力,大概也取决于浏览器。在

相关问题 更多 >