联系客户支持
我们提供全天候 24/7的英语、俄语、中文、越南语和葡萄牙语支持。填写下面的表格,我们将尽快与您联系!
最受欢迎主题: Multilogin X, Multilogin 6,
Selenium浏览器自动化在Multilogin 6
由 Yana Shcharbina 编写
最近一次更新时间:December 16th, 2024
浏览器自动化允许您在Multilogin 6的浏览器配置文件中自动执行任务。从创建简单的自动化脚本到复杂的Web爬虫,可以搜索、收集Web数据并与之交互。
Multilogin 6浏览器自动化基于Selenium WebDriver。
通常情况下,如果您运行Selenium代码,首先将连接到Firefox(Gecko)或Chrome驱动,然后设置您所需要的功能。而将Multilogin与Selenium代码结合使用时,您无需这样操作。
您将使用Remote Web Driver程序,通过本地端口连接到Multilogin 6应用或某浏览器配置文件,设置所需功能,在预定义的浏览器配置文件中执行Selenium命令。
支持的语言
Selenium框架提供了多种可搭配使用的语言,因此Multilogin 6自动化也可以在多种编码语言上运行。但是目前,我们仅为Python供技术支持。
定义Multilogin 6端口
您需要提前定义软件端口以使用Selenium自动化。以下是定义端口的方法:
- 前往C:\Users\%username%\.multiloginapp.com路径并打开app.properties文件。
- 添加此语句:
multiloginapp.port=[PORT_NUMBER]
。
端口号的范围为10000 ~ 49151。
- 保存 app.properties 文件。
随后,您就可以通过定义的端口连接到Multiogin 6了。
更多相关信息,您可以查阅此指导文章。
Python 案例
from selenium import webdriver
from selenium.webdriver.chromium.options import ChromiumOptions
from selenium.webdriver.firefox.options import Options
import requests
#TODO 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 of using Stealthfox browser
#driver = webdriver.Remote(command_executor=json['value'], options=Options())
#Perform automation
driver.get('https://multilogin.com/')
print(driver.title)
driver.quit()