Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How do I get the URL of the active tab in Firefox/IE/Chrome?

Reply
Thread Tools

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

 
 
He Jibo
Guest
Posts: n/a
 
      11-28-2010
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/3631
.... -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/ ... Bar-Python
http://blogs.msdn.com/b/oldnewthing/arc ... 35657.aspx
http://mail.python.org/pipermail/python ... 02040.html
http://code.activestate.com/recipes/302 ... lass-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()
 
Reply With Quote
 
 
 
 
Tim Harig
Guest
Posts: n/a
 
      11-28-2010
On 2010-11-28, He Jibo <(E-Mail Removed)> wrote:
> 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.


It would be beneficial to know what your ultimate goal is. The
"InternetExplorer.Application" automation object doesn't contain any way to
manipulate tabs directly; but, there are likely less direct methods of
achieving whatever you are trying to accomplish if you let us know what
that is.
 
Reply With Quote
 
 
 
 
Michel Claveau - MVP
Guest
Posts: n/a
 
      11-29-2010
Hello!

> The "InternetExplorer.Application" automation object doesn't contain
> any way to manipulate tabs directly


False. Try this example:
import win32com.client
for instance in win32com.client.Dispatch('{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'):
print instance," URL :",instance.LocationURL

@-salutations
--
Michel Claveau


 
Reply With Quote
 
Tim Harig
Guest
Posts: n/a
 
      11-29-2010
On 2010-11-29, Michel Claveau - MVP <(E-Mail Removed)> wrote:
> Hello!
>
>> The "InternetExplorer.Application" automation object doesn't contain
>> any way to manipulate tabs directly

>
> False. Try this example:
> import win32com.client
> for instance in win32com.client.Dispatch('{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'):
> print instance," URL :",instance.LocationURL


A Shell collection object != a InternetExplorer.Application object.
The problem with using a ShellWindows object is that you could easily
connect to the wrong instance, especially since the OP doesn't know the
LocationURL of the instance that he is looking for. That is why I asked
for clarification. Once we know what the OP is trying to do, we can
make sure that he has a reliable method to connect to the proper instance.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How do I get the URL of the active tab in Firefox/IE/Chrome? He Jibo Python 0 11-29-2010 05:53 AM
How do I move from tab to tab? Bobby Firefox 11 12-21-2005 03:04 PM
Can you get firefox to open a tab by just clicking on the URL ? Mr Sheridan Firefox 3 01-15-2005 05:50 PM
Bug in Tabbrowser? (last tab always stays in tab list) Alexander Fischer Firefox 1 10-01-2004 07:40 AM



Advertisments