依照网上的设置,代码如下:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--profile-directory=Default')
options.add_argument('--user-data-dir=C:\Users\admin\AppData\Local\Google\Chrome\User Data\Profile 4')
browser = webdriver.Chrome(chrome_options=options)
报错信息如下:
Traceback (most recent call last):
File "C:/Users/admin/PycharmProjects/testdemo/555.py", line 11, in
browser = webdriver.Chrome(chrome_options=options)
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in init
desired_capabilities=desired_capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot create default profile directory
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.14393 x86_64)