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

Discussion in 'Python' started by He Jibo, Nov 29, 2010.

  1. He Jibo

    He Jibo Guest

    Hi,
    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,
    http://stackoverflow.com/questions/...e-url-of-the-visible-tab-in-firefox-ie-chrome

    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.

    '''
    http://efreedom.com/Question/1-2555905/Get-Internet-Explorer-Address-Bar-Python
    http://blogs.msdn.com/b/oldnewthing/archive/2005/07/05/435657.aspx
    http://mail.python.org/pipermail/python-win32/2004-June/002040.html
    http://code.activestate.com/recipes/302324-browser-automation-tool-py-class-file/
    '''
    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

    else:
    print "no ie window"

    if __name__ == '__main__':
    main()
     
    He Jibo, Nov 29, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Hale
    Replies:
    0
    Views:
    316
    Paul Hale
    Sep 4, 2008
  2. Disc Magnet
    Replies:
    2
    Views:
    3,449
    123Jim
    May 14, 2010
  3. He Jibo
    Replies:
    3
    Views:
    1,058
    Tim Harig
    Nov 29, 2010
  4. Arihan Sinha
    Replies:
    4
    Views:
    257
    Heesob Park
    Sep 28, 2010
  5. goldtech
    Replies:
    2
    Views:
    102
    goldtech
    Jul 3, 2013
Loading...

Share This Page