Python刷新HTML文档
我有一个 HTML 文档,可以通过将其指定为我想要打开的 URL,使用 webbrowser 模块打开该文档,效果很好。我希望该文档能够使用将要运行的 Python 脚本来刷新自身(以重新打开自身以外的方式)。我尝试在 webbrowser 模块中设置 new=0 ,但它只是在浏览器中打开一个新选项卡。有什么办法可以做到这一点吗?
I have an HTML document that I am able to open with the webbrowser module by specifying it as the URL that I want to open, this works fine. I want this document to be able to refresh itself (in a way other than reopening itself) with a Python script that will be running. I've tried setting new=0 in the webbrowser module, but it just opens a new tab in the browser anyway. Is there any way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决问题的两种方法:
JavaScript - 将其添加到页面底部并更新文件名路径,它将在同一选项卡中每 10 秒进行一次完全重新加载。
Python 选项 - 使用 Selenium。为此,您需要下载与您所需的浏览器兼容的 driver.exe,并在代码中链接到它。使用 time.sleep(10) 在 do while true 循环中将打开的页面分配给驱动程序。
如果你坚持使用 python,我可以写出更详细的代码,但 JavaScript 解决方案应该可以工作。
Two ways to solve the issue:
JavaScript - Add this to the bottom of your page with the filename path updated, it will do a full reload every 10 seconds in the same tab.
Python option - use Selenium. For that you will need to download a driver.exe compatible with the browser you need, link to it in your code. Assign the open page to the driver in a do while true loop with a time.sleep(10).
If you insist on using python, I can write out the code in more detail, but the JavaScript solution should work.
Ajax (Javascript) 用于刷新 html 文档而无需重新加载。
Ajax (Javascript) is used to refresh-html-document without reload .