環境
ubuntu server20.04
Python3.8
selenium:4.6.1
chrome:s108.0.5359.71
さくらのVPSでubuntu server20.04を選択し、
VNC接続によるGUI環境を作ってあります。
(ここを見ながらVNCのGUI環境を作りました)
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-20-04-ja
chromeもインストールして、
VNC上でchromeブラウザを起動して閲覧する事はできるのですが、
seleniumでchromeブラウザを起動しようとしてもうまくいきません。
ヘッドレスモードで起動する事はできたのですが、
非ヘッドレスモードで起動する事はできないのでしょうか?
(ブラウザを起動してその動きが見たいのです)
どなたかご存じの方がいらっしゃいましたら、
どうぞよろしくお願い致します。
コード(ヘッドレスならエラーにならない)
from selenium import webdriver
from selenium.webdriver import ChromeOptions
import chromedriver_binary
options = ChromeOptions()
options.add_argument("--headless") #この行を削除してブラウザを起動させたい
url = "https://www.google.com/?hl=ja"
driver = webdriver.Chrome(options=options)
driver.get(url)
print(driver.title)
driver.quit()
ヘッドレスの行を削除して実行すると出るエラー
Traceback (most recent call last):
File "test3.py", line 9, in <module>
driver = webdriver.Chrome(options=options)
File "/home/ubuntu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in init
super().init(
File "/home/ubuntu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 106, in init
super().init(
File "/home/ubuntu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 288, in init
self.start_session(capabilities, browser_profile)
File "/home/ubuntu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 381, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/ubuntu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "/home/ubuntu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x558e63273563 <unknown>
#1 0x558e63032667 <unknown>
#2 0x558e6305abb7 <unknown>
#3 0x558e63056d90 <unknown>
#4 0x558e630976b7 <unknown>
#5 0x558e6309705f <unknown>
#6 0x558e6308eef3 <unknown>
#7 0x558e6306249e <unknown>
#8 0x558e630635ae <unknown>
#9 0x558e632c2fde <unknown>
#10 0x558e632c64c4 <unknown>
#11 0x558e632a978e <unknown>
#12 0x558e632c7393 <unknown>
#13 0x558e6329c665 <unknown>
#14 0x558e632e8108 <unknown>
#15 0x558e632e8296 <unknown>
#16 0x558e63303183 <unknown>
#17 0x7f476f507609 start_thread
回答1件
あなたの回答
tips
プレビュー