0

I work with python 3.7 on windows and I want to write a script that print the actual active urls on browsers (chrome and firefox), I found the script: import webbrowser webbrowser.open(the url) but this script allows to open the url not to find the active urls. can someone help me

1

2 Answers 2

1

Here you need to download and install pywin32 and import these modules in your script like this -

import win32gui
import win32con

#to get currently active windows
window = win32gui.GetForegroundWindow

Or to get the Google Chrome window handle

win32gui.FindWindow

Sign up to request clarification or add additional context in comments.

Comments

0

You can use selenium module and loop through all open tabs.

This code prints all open tabs of chrome and firefox:

from selenium import webdriver

chromeDriver = webdriver.Chrome()
firefoxDriver = webdriver.Firefox()


for handle in chromeDriver.window_handles[0]:
    chromeDriver.switch_to.window(handle)
    print(chromeDriver.current_url)

for handle in firefoxDriver.window_handles[0]:
    firefoxDriver.switch_to.window(handle)
    print(firefoxDriver.current_url)


Note:

This code is inefficient and should change to use only one loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.