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?
            Asked
            
        
        
            Active
            
        
            Viewed 1.7k times
        
    6
            
            
        - 
                    1If *new* is 0 it should open it in the same tab - and not a new tab. AFAIK there is no other way of doing this. – Russell Dias Jan 10 '12 at 02:55
- 
                    1You need to refresh the page with some Javascript, which [is pretty simple](http://www.google.ca/webhp?sourceid=chrome-instant&ix=seb&ie=UTF-8&ion=1#sclient=psy-ab&hl=en&site=webhp&source=hp&q=refresh%20page%20with%20javascript&pbx=1&oq=&aq=&aqi=&aql=&gs_sm=&gs_upl=&fp=24d5377621950837&ion=1&ion=1&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=24d5377621950837&biw=1280&bih=679&ion=1). There is no way to do this with Python other than what you already mentioned. – Bartek Jan 10 '12 at 03:01
- 
                    Thanks, I'll look into some Javascript. – Dan Doe Jan 10 '12 at 03:04
2 Answers
0
            
            
        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.
<script>
setInterval(function(){
window.open('file:///C:/YOURPATH/file2.html', "_self")
}, 10000);
</script>
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.
 
    
    
        Vitalijs Arkulinskis
        
- 311
- 5
- 5
- 
                    1
- 
                    Seemed to be trending again, thought I give it a shot. Another idea would be to use a flask server that pushes data updates only when those are available without reloading the page unnecessarily. – Vitalijs Arkulinskis Jan 05 '20 at 05:01
 
    