pythonpython-2.7browsergeturl

Get current URL from browser using python


I am running an HTTP server which serves a bitmap according to the dimensions in the browser URL i.e localhost://image_x120_y30.bmp. My server is running in infinite loop and I want to get the URL any time user requests for BITMAP, and at the end I can extract the image dimensions from the URL.

The question asked here:

How to get current URL in python web page?

does not address my problem as I am running in infinite loop and I want to keep on getting the current URL so I can deliver the requested BITMAP to the user.


Solution

  • If to use Selenium for web navigation:

    from selenium import webdriver
    driver = webdriver.Firefox()
    print (driver.current_url)