【发布时间】:2021-04-27 23:55:22
【问题描述】:
我希望我的程序打开默认的 chrome 配置文件,然后获取 youtube。 我可以让它打开 youtube(在新的 chrome 浏览器中),或者打开默认的 chrome 配置文件,但不能同时打开。 (而且我没有同时运行两个驱动程序变量)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
print('starting')
print('getting driver')
exec_path= "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" # exec path from chrome://version
profilePath= 'C:\\Users\\MyName\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1' #profile path from chrome://version
chromePath= 'C:\\Users\\MyName\\OneDrive\\Documents\\Python programming\\chromedriver.exe' #path to driver
options= webdriver.ChromeOptions()
options.add_argument(profilePath)
print('options add argument...')
### Run one or the other ###
driver = webdriver.Chrome(executable_path= chromePath , options=options) #gets youtube
driver = webdriver.Chrome(executable_path= exec_path, options=options) #gets chrome profile
print('webdriver getting youtube...')
driver.get("https://www.youtube.com/")
当我运行获取 chrome 配置文件的驱动程序行时,我收到错误:
Traceback(最近一次调用最后一次): 文件“C:\Users\MyName\OneDrive\Documents\Python 编程\Web 自动化\webAuto.py”,第 24 行,在 driver = webdriver.Chrome(executable_path= exec_path, options=options) #获取 chrome 配置文件 init 中的文件“C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py”,第 73 行 self.service.start() 文件“C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py”,第 104 行,开始 raise WebDriverException("无法连接到服务 %s" % self.path) selenium.common.exceptions.WebDriverException:消息:无法连接到服务 C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
【问题讨论】:
标签: python selenium google-chrome selenium-webdriver