環境
ubuntu 18.04 LTS
Python 3.6.9
WSL
1$ which chromedriver 2/usr/local/bin/chromedriver 3$ chromedriver --version 4ChromeDriver 78.0.3904.105
WSL
1$ which google-chrome 2/usr/bin/google-chrome 3$ google-chrome --version 4Google Chrome 78.0.3904.108
chromedriver.pyに書いた内容
1つ目
python3
1from time import sleep 2from selenium import webdriver 3from selenium.webdriver.chrome.options import Options 4 5options = Options() 6options.add_argument('--headless') 7options.add_argument('--no-sandbox') 8options.add_argument("--user-data-dir=/home/jack/.config/google-chrome/Default") #Path to your chrome profile 9 10driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options) 11 12driver.get('https://www.google.com') 13driver.save_screenshot('screenshot.png') 14 15sleep(5) 16 17driver.quit()
実行すると、
WSL
1$ python3 chromedriver.py 2Traceback (most recent call last): 3 File "chromedriver.py", line 10, in <module> 4 driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options) 5 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ 6 desired_capabilities=desired_capabilities) 7 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ 8 self.start_session(capabilities, browser_profile) 9 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session 10 response = self.execute(Command.NEW_SESSION, parameters) 11 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute 12 self.error_handler.check_response(response) 13 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response 14 raise exception_class(message, screen, stacktrace) 15selenium.common.exceptions.WebDriverException: 16Message: unknown error: Could not remove old devtools port file. 17Perhaps the given user-data-dir at /home/jack/.config/google-chrome/Default 18is still attached to a running Chrome or Chromium process.
2つ目
python3
1from time import sleep 2from selenium import webdriver 3from selenium.webdriver.chrome.options import Options 4 5options = Options() 6options.add_argument('--headless') 7options.add_argument('--no-sandbox') 8options.add_argument("--user-data-dir=/usr/bin/google-chrome") #Path to your chrome profile 9 10driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options) 11 12driver.get('https://www.google.com') 13driver.save_screenshot('screenshot.png') 14 15sleep(5) 16 17driver.quit()
実行すると、
WSL
1$ python3 chromedriver.py 2Traceback (most recent call last): 3 File "chromedriver.py", line 10, in <module> 4 driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options) 5 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ 6 desired_capabilities=desired_capabilities) 7 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ 8 self.start_session(capabilities, browser_profile) 9 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session 10 response = self.execute(Command.NEW_SESSION, parameters) 11 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute 12 self.error_handler.check_response(response) 13 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response 14 raise exception_class(message, screen, stacktrace) 15selenium.common.exceptions.WebDriverException: Message: unknown error: cannot create default profile directory
3つ目
python3
1from time import sleep 2from selenium import webdriver 3from selenium.webdriver.chrome.options import Options 4 5options = Options() 6options.add_argument('--headless') 7options.add_argument('--no-sandbox') 8 9driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options) 10 11driver.get('https://www.google.com') 12driver.save_screenshot('screenshot.png') 13 14sleep(5) 15 16driver.quit()
実行すると、
WSL
1$ python3 chromedriver.py 2Traceback (most recent call last): 3 File "chromedriver.py", line 10, in <module> 4 driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options) 5 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ 6 desired_capabilities=desired_capabilities) 7 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ 8 self.start_session(capabilities, browser_profile) 9 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session 10 response = self.execute(Command.NEW_SESSION, parameters) 11 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute 12 self.error_handler.check_response(response) 13 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response 14selenium.common.exceptions.WebDriverException: Message: unknown error: cannot create default profile directory 15jack@kanzaki:/mnt/c/Users/abcxy/.vscode/python$ 16jack@kanzaki:/mnt/c/Users/abcxy/.vscode/python$ python3 chromedriver.py 17Traceback (most recent call last): 18 File "chromedriver.py", line 12, in <module> 19 driver.save_screenshot('screenshot.png') 20 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1055, in save_screenshot 21 return self.get_screenshot_as_file(filename) 22 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1032, in get_screenshot_as_file 23 png = self.get_screenshot_as_png() 24 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1064, in get_screenshot_as_png 25 return base64.b64decode(self.get_screenshot_as_base64().encode('ascii')) 26 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1074, in get_screenshot_as_base64 27 return self.execute(Command.SCREENSHOT)['value'] 28 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute 29 self.error_handler.check_response(response) 30 File "/home/jack/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response 31 raise exception_class(message, screen, stacktrace) 32selenium.common.exceptions.WebDriverException: Message: chrome not reachable 33 (Session info: headless chrome=78.0.3904.108)
質問
以上、自分が挑戦してみたことです。
コードの方に問題があるのか、
または、google-chromeなどのファイルや、ディレクトリの設置方法に問題があるのか、
疑問に思っています。
ご回答の程、よろしくお願いします。