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?

2 Answers 2

3

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:]
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.