under Ubuntu, use python3.5 + selenium 3.9.0. When you open the browser, you want to load cookie, and check the directory of
under win. It is in: C:UsersusernameAppDataLocalGoogleChromeUser Data, and then I refer to this to find my directory under: / home/username/.config/google-chrome (the reason is that the file structures in these two directories are almost the same).
but the error will be reported after running this way. The error is as follows:
File "test.py", line 18, in < module >
driver=webdriver.Chrome(chrome_options=chrome_options)
File "/ usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in init
desired_capabilities=desired_capabilities)
File "/ usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in init
self.start_session(desired_capabilities, browser_profile)
File "/ usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/ usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/ usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
here is my code:
from selenium import webdriver
import os
import time
from pyvirtualdisplay import Display
cookie_dir="/ home/username/.config/google-chrome"-sharp corresponds to the user data storage path of your chrome
chrome_options=webdriver.ChromeOptions ()
chrome_options.add_argument ("--profile-directory=Default")
chrome_options.add_argument ("--user-data-dir=" + os.path.abspath (cookie_dir))
driver=webdriver.Chrome (chrome_options=chrome_options)
driver.maximize_window ()
driver.get ("https://www.baidu.com/")
if you remove the line chrome_options.add_argument ("--user-data-dir=" + os.path.abspath (cookie_dir)), you can open it normally.
here is a screenshot of the code:
has the Great God encountered this situation? Thank you very much