Mat*_*ttV 2 python firefox firefox-marionette
我很难通过木偶创建两个firefox实例.有一个实例正常工作:
启用带有木偶的Firefox启动:
firefox.exe -marionette
Run Code Online (Sandbox Code Playgroud)
用python控制它:
from marionette import Marionette
client = Marionette('localhost', port=2828)
client.start_session()
client.execute_script("alert('o hai there!');")
Run Code Online (Sandbox Code Playgroud)
现在我想添加第二个客户端和当前客户端,快速搜索导致--address命令:
firefox.exe -marionette --address=localhost:2829
Run Code Online (Sandbox Code Playgroud)
试图通过python控制它:
from marionette import Marionette
client = Marionette('localhost', port=2829)
client.start_session()
client.execute_script("alert('o hai there!');")
Run Code Online (Sandbox Code Playgroud)
但是,我似乎无法使其工作:
error: [Errno 10061] No connection could be made because the target machine actively refused it
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
您必须使用不同的配置文件使firefox侦听不同的端口.
编辑<path-to-profile>/prefs.js
添加以下内容并在firefox未使用此配置文件时保存;
user_pref("marionette.defaultPrefs.port", 2829);
Run Code Online (Sandbox Code Playgroud)
现在,启动firefox为;
firefox -marionette --profile <path-to-profile> --new-instance&
Run Code Online (Sandbox Code Playgroud)
创建新的个人资料;
$ mkdir new_profile
$ firefox --profile new_profile --new-instance
Run Code Online (Sandbox Code Playgroud)
并关闭Firefox.现在你有了new_profile/prefs.js