Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want my program to open up the default chrome profile and then get youtube. I can make it either open youtube (in a new chrome browser), or open the default chrome profile, but not both. (And no im not running both driver variables)

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/")

when I run the driver line that gets the chrome profile I get the error:

Traceback (most recent call last): File "C:UsersMyNameOneDriveDocumentsPython programmingWeb automationwebAuto.py", line 24, in driver = webdriver.Chrome(executable_path= exec_path, options=options) #gets chrome profile File "C:UsersMyNameAppDataLocalProgramsPythonPython39libsite-packagesseleniumwebdriverchromewebdriver.py", line 73, in init self.service.start() File "C:UsersMyNameAppDataLocalProgramsPythonPython39libsite-packagesseleniumwebdrivercommonservice.py", line 104, in start raise WebDriverException("Can not connect to the Service %s" % self.path) selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:Program Files (x86)GoogleChromeApplicationchrome.exe

question from:https://stackoverflow.com/questions/65863395/chromedriver-wont-get-website-python-selenium

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
331 views
Welcome To Ask or Share your Answers For Others

1 Answer

As per your question and your code trials if you want to open a Chrome with the customized Chrome Profile, Try using below code.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('C:\Users\MyName\AppData\Local\Google\Chrome\User Data\Profile 1' )
driver = webdriver.Chrome(executable_path='C:\Users\MyName\OneDrive\Documents\Python programming\chromedriver.exe', chrome_options=options)
driver.get("https://www.youtube.com/")

Here you will find a detailed discussion on How to open a Chrome Profile through Python


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...