Refresh a local web page using Python

后端 未结 5 1338
自闭症患者
自闭症患者 2021-01-04 12:24

I\'m using Python to gather some information, construct a very simple html page, save it locally and display the page in my browser using webbrowser.open(\'file:///c:/testfi

相关标签:
5条回答
  • 2021-01-04 12:48

    The LivePage extension for Chrome. You can write to a file, then LivePage will monitor it for you. You can also optionally refresh on imported content like CSS. Chrome will require that you grant permissions on local file:// urls.

    (I'm unaffiliated with the project.)

    0 讨论(0)
  • 2021-01-04 12:54

    It looks like several people have asked this in the past but here is a link that sums it up.

    Python refresh HTML document

    But webbrowser.open( url, new=0 ) should open the page in the current window and not initialize a new one.

    0 讨论(0)
  • 2021-01-04 13:10

    If you're going to need a refresh on the same tab, you'll need selenium webdriver. After installing selenium using pip, you can use the following code

        from selenium import webdriver
    import time
    import urllib
    import urllib2
    
    x=raw_input("Enter the URL")
    refreshrate=raw_input("Enter the number of seconds")
    refreshrate=int(refreshrate)
    driver = webdriver.Firefox()
    driver.get("http://"+x)
    while True:
        time.sleep(refreshrate)
        driver.refresh()
    

    This will open the url and refresh the tab every refreshrate seconds

    0 讨论(0)
  • 2021-01-04 13:12

    I use pyautogui module to refresh the browser page. It's one liner:

    import pyautogui
    
    pyautogui.hotkey('f5') #Simulates F5 key press = page refresh
    
    0 讨论(0)
  • 2021-01-04 13:13

    Keep it very short, as simple as:

    from selenium import webdriver
    import time
    
    driver = webdriver.Firefox()
    
    driver.get('URL')
    while True:
        time.sleep(20)
        driver.refresh()
    driver.quit()
    
    0 讨论(0)
提交回复
热议问题