Rotating different HTML files through a single browser tab with the Python webbrowser module | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Rotating different HTML files through a single browser tab with the Python webbrowser module

I'm trying to make the html files contained in a folder appear in the browser in turns (30 seconds each, for example), but always in the same window and tab, replacing each other. So far I've tried with webbrowser, using Firefox, Chrome and Chromium, but there's no way. Either it opens the files in new windows or in new tabs. I leave the code in case someone else comes up with another solution: from os import scandir, getcwd import webbrowser import time rout= getcwd() docs = [doc.name for doc in scandir(rout) if doc.is_file() and doc.name.endswith(".html")] for doc in docs: doc = rout + '\\' + doc webbrowser.open(doc, new=0) time.sleep(30) https://code.sololearn.com/cPRP0CyoDoSL/?ref=app

12th Mar 2019, 11:06 PM
Felipe Santa-Cruz
Felipe Santa-Cruz - avatar
4 Answers
+ 3
I see you already tried new=0 parameter. I guess the webbrowser library is rather unsophisticated for this. I found a thread on reddit where selenium was the suggested solution. https://www.reddit.com/r/learnpython/comments/4psxme/overwrite_the_current_url_in_a_browser_with_a_new/ Maybe another way would be, if you don't insist on a pure python solution, to open one HTML page with python, where a JavaScript program switches the contents.
14th Mar 2019, 6:10 PM
Tibor Santa
Tibor Santa - avatar
+ 3
https://github.com/cztomczak/cefpython Could also be an option. This is a web rendering engine you can embed in any python gui such as tkinter, qt, or kivy
14th Mar 2019, 6:36 PM
Tibor Santa
Tibor Santa - avatar
+ 2
I expect it should be possible in JS with a few lines of code, but I am not proficient enough either to help.
14th Mar 2019, 6:46 PM
Tibor Santa
Tibor Santa - avatar
0
The problem with selenium is web driver for Firefox it's not working well in raspberry pi 3b+. Any way, I'm trying everything to make it work. The problem with the second of your solution is that I don't have any Javascript knowledge :(. It's in my task list. Anyway, would it be very difficult to do it on javascript?
14th Mar 2019, 6:38 PM
Felipe Santa-Cruz
Felipe Santa-Cruz - avatar