How do I get the URL of the active tab in Firefox/IE/Chrome?


He Jibo

I am writing a small program, which needs to get the URL of the active
tab in either of firefox, internet exploerer or chrome.
My need is similar as the one posted at,

I did a lot of Googling, and get the following code. The following
code can get the url of the first tab in internet explorer. My
question is, how can I get the url of the current active tab? Thanks.

from win32com.client import Dispatch
import win32api, win32con,win32gui

SHELL = Dispatch("Shell.Application")

def get_ie(shell):
for win in shell.Windows():
# print win
if win.Name == "Windows Internet Explorer":
return win
return None

def main():
ie = get_ie(SHELL)
if ie:
print ie.LocationURL
print ie.LocationName
print ie.ReadyState
print ie
print ie.Document.title
print ie.Document.location
print ie.Document.forms

# title = win32gui.GetWindowText(ie)
# print title

print "no ie window"

if __name__ == '__main__':


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question