tags:

views:

1240

answers:

4

I want to know what is the current url of active tab in running firefox instance from python module. Does FireFox have any API for this and does python know to work with it?

+1  A: 

If on windows you can use win32com

import win32clipboard
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate('Some Application Title')

Then use shell.SendKeys to do a ctrl+l and a ctrl+c

Then read the string in the clipboard.

It's horkey though it will work, alternatly you can use something like AutoIt an compile the code to an exe that you can work with.

Hope this helps.

chews
A: 

I think i found something that can help me https://developer.mozilla.org/en/PyXPCOM

A: 

There is also a webbrowser module in python, but it seems to only allow you to open new windows/tabs.

monkut
+1  A: 

The most convenient way maybe insatll a firefox extension to open up a tcp service, then you can exchange info with firefox.

mozrepl can set up a telnet service, you can call js-like command to get info.

With telnetscript (http: //code.activestate.com/recipes/152043/), you can write:


import telnetscript

script = """rve
w content.location.href;
ru repl>
w repl.quit()
cl
"""


conn = telnetscript.telnetscript( '127.0.0.1', {}, 4242 )
ret = conn.RunScript( script.split( '\n' )).split( '\n' )
print ret[-2][6:]