Hi,<br>
I am writing a small program, which needs to get the URL of the active<br>
tab in either of firefox, internet exploerer or chrome.<br>
My need is similar as the one posted at,<br>
<a href="http://stackoverflow.com/questions/3631216/how-do-i-get-the-url-of-the-visible-tab-in-firefox-ie-chrome" target="_blank">http://stackoverflow.com/questions/3631216/how-do-i-get-the-url-of-the-visible-tab-in-firefox-<span class="il">ie</span>-chrome</a><br>
<br>
I did a lot of Googling, and get the following code. The following<br>
code can get the url of the first tab in internet explorer. My<br>
question is, how can I get the url of the current active tab? Thanks.<br>
<br>
'''<br>
<a href="http://efreedom.com/Question/1-2555905/Get-Internet-Explorer-Address-Bar-Python" target="_blank">http://efreedom.com/Question/1-2555905/Get-Internet-Explorer-Address-Bar-Python</a><br>
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/07/05/435657.aspx" target="_blank">http://blogs.msdn.com/b/oldnewthing/archive/2005/07/05/435657.aspx</a><br>
<a href="http://mail.python.org/pipermail/python-win32/2004-June/002040.html" target="_blank">http://mail.python.org/pipermail/python-win32/2004-June/002040.html</a><br>
<a href="http://code.activestate.com/recipes/302324-browser-automation-tool-py-class-file/" target="_blank">http://code.activestate.com/recipes/302324-browser-automation-tool-py-class-file/</a><br>
'''<br>
from win32com.client import Dispatch<br>
import win32api, win32con,win32gui<br>
<br>
<br>
SHELL = Dispatch("Shell.Application")<br>
<br>
def get_ie(shell):<br>
for win in shell.Windows():<br>
# print win<br>
if win.Name == "Windows Internet Explorer":<br>
return win<br>
return None<br>
<br>
def main():<br>
<span class="il">ie</span> = get_ie(SHELL)<br>
if <span class="il">ie</span>:<br>
print <span class="il">ie</span>.LocationURL<br>
print <span class="il">ie</span>.LocationName<br>
print <span class="il">ie</span>.ReadyState<br>
print <span class="il">ie</span><br>
print <span class="il">ie</span>.Document.title<br>
print <span class="il">ie</span>.Document.location<br>
print <span class="il">ie</span>.Document.forms<br>
<br>
# title = win32gui.GetWindowText(<span class="il">ie</span>)<br>
# print title<br>
<br>
else:<br>
print "no <span class="il">ie</span> window"<br>
<br>
if __name__ == '__main__':<br>
main()<br clear="all">---------------------------<br>He Jibo<br>Department of Psychology,<br>Beckman Institute for Advanced Science and Technology<br>University of Illinois, Urbana Champaign,<br>603 East Daniel St.,<br>
Champaign, IL 61820<br>website: <a href="http://www.hejibo.info">www.hejibo.info</a><br><br>