使用Selenium同时打开多个Chrome配置文件可以通过以下步骤实现:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
options1 = Options()
options1.add_argument("--user-data-dir=/path/to/profile1")
options2 = Options()
options2.add_argument("--user-data-dir=/path/to/profile2")
# 可以根据需要创建更多的配置文件选项对象
在上述代码中,--user-data-dir
参数指定了Chrome配置文件的路径。请将/path/to/profile1
和/path/to/profile2
替换为实际的配置文件路径。
driver1 = webdriver.Chrome(options=options1)
driver2 = webdriver.Chrome(options=options2)
# 可以根据需要创建更多的浏览器实例
在上述代码中,options
参数传入了之前创建的配置文件选项对象。
driver1.get("https://www.example1.com")
driver2.get("https://www.example2.com")
# 可以根据需要在不同的浏览器实例上执行其他操作
在上述代码中,get()
方法用于打开指定的网页。
通过以上步骤,你可以同时打开多个Chrome配置文件,并在每个浏览器实例上执行不同的操作。
注意:以上代码示例中的路径和网址仅作为示例,请根据实际情况进行修改。另外,为了保证稳定性和安全性,建议在使用Selenium时遵循相关的使用规范和最佳实践。
领取专属 10元无门槛券
手把手带您无忧上云