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?
我想知道从python模块运行firefox实例时活动选项卡的当前url是什么。 FireFox有没有这方面的API,python知道可以使用吗?
3 个解决方案
#1
The most convenient way maybe insatll a firefox extension to open up a tcp service, then you can exchange info with firefox.
最方便的方法可能是使用firefox扩展来打开tcp服务,然后你可以用firefox交换信息。
mozrepl can set up a telnet service, you can call js-like command to get info.
mozrepl可以设置telnet服务,你可以调用类似js的命令来获取信息。
With telnetscript (http: //code.activestate.com/recipes/152043/), you can write:
使用telnetscript(http://code.activestate.com/recipes/152043/),您可以编写:
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:]
#2
If on windows you can use win32com
如果在Windows上你可以使用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
然后用shell.SendKeys做一个ctrl + l和一个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.
虽然它会起作用,但它可以使用像AutoIt这样的代码将代码编译为可以使用的exe。
Hope this helps.
希望这可以帮助。
#3
There is also a webbrowser module in python, but it seems to only allow you to open new windows/tabs.
python中还有一个webbrowser模块,但似乎只允许你打开新的windows / tabs。
#1
The most convenient way maybe insatll a firefox extension to open up a tcp service, then you can exchange info with firefox.
最方便的方法可能是使用firefox扩展来打开tcp服务,然后你可以用firefox交换信息。
mozrepl can set up a telnet service, you can call js-like command to get info.
mozrepl可以设置telnet服务,你可以调用类似js的命令来获取信息。
With telnetscript (http: //code.activestate.com/recipes/152043/), you can write:
使用telnetscript(http://code.activestate.com/recipes/152043/),您可以编写:
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:]
#2
If on windows you can use win32com
如果在Windows上你可以使用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
然后用shell.SendKeys做一个ctrl + l和一个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.
虽然它会起作用,但它可以使用像AutoIt这样的代码将代码编译为可以使用的exe。
Hope this helps.
希望这可以帮助。
#3
There is also a webbrowser module in python, but it seems to only allow you to open new windows/tabs.
python中还有一个webbrowser模块,但似乎只允许你打开新的windows / tabs。