在Multilogin 6 中使用Selenium执行浏览器自动化
想要在Multilogin 6 中自动执行任务吗?无论您是编写脚本还是构建高级网络爬虫,浏览器自动化从未如此简单!
通常使用Selenium时,您必须手动连接到浏览器驱动程序(例如 Firefox 或Chrome )。但是使用Multilogin 6,您可以省去这个麻烦:
- 使用 Remote WebDriver 直接连接到Multilogin浏览器配置文件
- 轻松设置您想要的功能
- 轻松运行Selenium命令
Multilogin 6 利用Selenium WebDriver ,因此您无需任何额外设置即可顺利执行自动化脚本。
步骤 1:使用受支持的编程语言
由于Selenium框架支持多种编程语言,因此您可以使用您喜欢的任何语言运行Multilogin 6 自动化。
虽然Selenium可以支持多种编程语言,但目前我们的技术支持仅针对Python提供服务。
第二步:定义应用程序监听端口
Define ports MLA CN
以下是在app.properties
文件中预定义默认监听端口的方法:
- 打开Multilogin
- 前往“我的帐户”
- 点击“打开日志目录” – 这将打开文件夹
/.multiloginapp.com/logs
- 导航至一个文件夹至
/.multiloginapp.com
- 使用任何文本编辑器打开
app.properties
- 添加新行来指定端口号:
multiloginapp.port=35000
- 保存更改
确保端口号介于 10000 和 49151 之间。
您还可以在.multiloginapp.com
文件夹中找到app.properties
文件:
- Windows :
C:\Users\%username%\.multiloginapp.com
- Linux :
/home/%username%/.multiloginapp.com
名%/.multiloginapp.com - macOS :
/Users/%username%/.multiloginapp.com
.multiloginapp.com
该文件夹可能被隐藏,具体取决于您的操作系统设置。要在 Mac 设备上显示此文件夹,您可以使用以下键盘快捷键:
-
Cmd + Shift + H
– 显示当前用户的文件夹 -
Cmd + Shift + .
(句点)– 显示隐藏文件夹和文件

步骤 3:查看代码示例
以下是一个 Python 代码示例,供您参考:
from selenium import webdriver
from selenium.webdriver.chromium.options import ChromiumOptions
from selenium.webdriver.firefox.options import Options
import requests
# TO-DO: replace with existing profile ID. Define the ID of the browser profile, where the code will be executed.
mla_profile_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
mla_url = 'http://127.0.0.1:35000/api/v1/profile/start?automation=true&profileId='+mla_profile_id
""" Send GET request to start the browser profile by profileId.
Returns response in the following format:'{"status":"OK","value":"http://127.0.0.1:XXXXX"}',
where XXXXX is the localhost port on which browser profile is launched.
Please make sure that you have Multilogin listening port set to 35000.
Otherwise please change the port value in the url string
"""
resp = requests.get(mla_url)
json = resp.json()
print(json)
# Instantiate the Remote Web Driver to connect to the browser profile launched by previous GET request
# In case of using Mimic browser
driver = webdriver.Remote(command_executor=json['value'], options=ChromiumOptions())
# In case you are using Stealthfox browser
#driver = webdriver.Remote(command_executor=json['value'], options=Options())
#Perform automation
driver.get('https://multilogin.com/')
print(driver.title)
driver.quit()