python - 使用 python 从 FireFox 检索当前 URL

标签 python firefox python-extensions

我想知道从 python 模块运行 firefox 实例时事件选项卡的当前 url 是什么。 FireFox 有没有这方面的 API,Python 知道如何使用它吗?

最佳答案

最方便的方法可能是安装一个firefox扩展,开通一个tcp服务,然后就可以和firefox交换信息了。

mozrepl可以设置一个telnet服务,可以调用类js命令获取信息。

使用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:]

关于python - 使用 python 从 FireFox 检索当前 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/493978/

相关文章:

python - 计算python中n维字段的邻居

Java 使用 API 或回调在 Firefox 中加载 URL?

便签本中的 Firefox 插件错误

javascript - 当 P 标签内部包含 BR 时,Execcommand justifyCenter 在 Firefox 中不起作用

python - Celery Python 中的异步子任务

python - pandas - get_dummies 乘以数量

python - 使用 pyqt 将输入输入到 .c 文件

python - 为 python 2.7 编译 libdnet

python - 使用 Tor 和 urllib python

numpy - 在 Windows 上使用 f2py 构建 64 位 Python 扩展