gpt4 book ai didi

python - 使用 Marionette 添加 Firefox 的第二个实例(更改端口)

转载 作者:行者123 更新时间:2023-11-28 21:46:43 25 4
gpt4 key购买 nike

我在通过木偶创建两个 Firefox 实例时遇到了很大的困难。有一个实例工作正常:

在启用 marionette 的情况下启动 Firefox:

firefox.exe -marionette

用python控制它:

from marionette import Marionette
client = Marionette('localhost', port=2828)
client.start_session()
client.execute_script("alert('o hai there!');")

现在我想在当前客户端旁边添加第二个客户端,quick search导致 --address 命令:

firefox.exe -marionette --address=localhost:2829

试图通过 python 控制它:

from marionette import Marionette
client = Marionette('localhost', port=2829)
client.start_session()
client.execute_script("alert('o hai there!');")

我似乎无法让它工作,但是:

error: [Errno 10061] No connection could be made because the target machine actively refused it

非常感谢任何帮助。

最佳答案

你必须使用不同的配置文件让 firefox 监听不同的端口。
编辑 <path-to-profile>/prefs.js添加以下内容并保存当 firefox 未使用此配置文件时

user_pref("marionette.defaultPrefs.port", 2829);

现在,启动 firefox;

firefox -marionette --profile <path-to-profile> --new-instance&

创建一个新的配置文件;

$ mkdir new_profile
$ firefox --profile new_profile --new-instance

然后关闭火狐。现在你将拥有 new_profile/prefs.js

关于python - 使用 Marionette 添加 Firefox 的第二个实例(更改端口),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com