質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Chrome

Google Chromeは携帯、テレビ、デスクトップなどの様々なプラットフォームで利用できるウェブブラウザです。Googleが開発したもので、Blink (レンダリングエンジン) とアプリケーションフレームワークを使用しています。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

Q&A

解決済

2回答

7333閲覧

Seleniumをheadlessモードなしで実行したときに「~exited abnormally.」と表示され動作しない

sg_mm

総合スコア0

Chrome

Google Chromeは携帯、テレビ、デスクトップなどの様々なプラットフォームで利用できるウェブブラウザです。Googleが開発したもので、Blink (レンダリングエンジン) とアプリケーションフレームワークを使用しています。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

0グッド

0クリップ

投稿2020/12/02 15:07

編集2020/12/04 05:13

前提・実現したいこと

ChromeDriverをChromeDriverManagerで自動でダウンロードし、seleniumをブラウザを開いたまま実行したいのですが、headlessモードでは問題なく実行でき、headless otptionをはずすとエラーとなります。
この原因についてご教示をお願いいたします。

なお、headlessモードにしたい理由としては以下コードでseleniumのブラウザを最後開いたままにしたいためです。

os.kill(driver.service.process.pid,signal.SIGTERM)

発生している問題・エラーメッセージ

[WDM] - Current google-chrome version is 87.0.4280 [WDM] - Driver [/root/.wdm/drivers/chromedriver/linux64/87.0.4280.20/chromedriver] found in cache … File "/mnt/c/workspace/src/main.py", line 58, in main driver = webdriver.Chrome(executable_path=ChromeDriverManager(response.text).install(), options=options) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.6/dist-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. (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.)

該当のソースコード

Python

1import requests 2from selenium import webdriver 3from webdriver_manager.chrome import ChromeDriverManager 4from webdriver_manager.utils import chrome_version 5 6def main(): 7 options = webdriver.ChromeOptions() 8 options.add_argument('--disable-dev-shm-usage') 9 options.add_argument('start-maximized') 10 options.add_argument('disable-infobars') 11 options.add_argument('--disable-extensions') 12 options.add_argument('--disable-gpu') 13 options.add_argument('--no-sandbox') 14 # options.add_argument('--headless') 15 16 version = chrome_version() 17 url = 'http://chromedriver.storage.googleapis.com/LATEST_RELEASE_' + version 18 19 response = requests.get(url) 20 driver = webdriver.Chrome(executable_path=ChromeDriverManager(response.text).install(), options=options) 21 driver.get('https://google.com')

試したこと

・optionの--headless つけ外し
・optionを一通り設定

補足情報(FW/ツールのバージョンなど)

  • Ubuntu 18.04 LTS
  • Python 3.6.9
  • Chromeブラウザ 87.0.4280.66
  • ChromeDriver(ChromeDriverManagerで自動ダウンロード) 87.0.4280.20

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

t_obara

2020/12/16 10:39

すでに最初の質問は解決しているのであれば、こちらを閉じて、その上で、再度助言に従い構成をきちんと提示した上で質問を別途投げてみてはいかがでしょうか。
guest

回答2

0

自己解決

ChromeDriverをChromeDriverManagerで自動でダウンロードし、seleniumをブラウザを開いたまま実行したいのですが、headlessモードでは問題なく実行でき、headless otptionをはずすとエラーとなります。

この原因についてご教示をお願いいたします。

結局当初から記載している上記については何も解決していないのですが、閉じたいと思います。

投稿2020/12/16 13:45

sg_mm

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

Dev-Toolsとのやりとりに以下のポートが必要です。オプションに追加してみてください。
(エラーに(unknown error: DevToolsActivePort file doesn't exist)って出てるので、これが原因かと)

options.add_argument("--remote-debugging-port=9222")

投稿2020/12/03 00:07

編集2020/12/03 00:09
Takeshi_Ueda

総合スコア183

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sg_mm

2020/12/03 12:09

Takeshi_Ueda様 ありがとうございます、DevToolsActivePortについては解消いたしました。 chromeに到達できないエラーが変わりに出てきました。 引き続き、アドバイスいただけますと幸いです。 ``` [WDM] - Current google-chrome version is 87.0.4280 [WDM] - There is no [linux64] chromedriver for browser 87.0.4280 in cache [WDM] - Trying to download new driver from http://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip [WDM] - Driver has been saved in cache [/root/.wdm/drivers/chromedriver/linux64/87.0.4280.88] … File "/mnt/c/workspace/src/main.py", line 59, in access_and_input driver = webdriver.Chrome(executable_path=ChromeDriverManager(response.text).install(), options=options) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.6/dist-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. (chrome not reachable) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) ```
Takeshi_Ueda

2020/12/03 14:00

最初の問題が解決したのなら、そこで解決済みにしてほしかったです。。 上記エラーに関しては、chromedriverが古い可能性とchromeとchromedriverのプロセスだらけになっているからだと推測します。 以下、参考までに。 https://qiita.com/tatetate55/items/e35e268bdf5ee0518324 ubuntu上でyum updateの実行と killall chrome killall chromedriver コマンドを実行してみてください。
sg_mm

2020/12/04 14:34

>headlessモードでは問題なく実行でき、headless otptionをはずすとエラーとなります。 当初記載していた上記が解決していないため続けさせていただきました。ご理解いただけますと幸いです。 いただいた修正内容ではchrome起動が失敗しているため、以下のように稼働しているプロセスが見つけられませんでした。 root@XXX:~# ps aux | grep chrome root 66 0.0 0.0 14856 1084 pts/0 S+ 20:00 0:00 grep --color=auto chrome root@XXX:~# killall chrome chrome: no process found root@XXX:~# killall chromedriver chromedriver: no process found
Takeshi_Ueda

2020/12/05 23:34

chromeが古いせいもあるので ubuntu上でsudo apt updateするなりしてchromeを最新化してみてください。
sg_mm

2020/12/08 14:44 編集

ありがとうございます、回答が遅くなり申し訳ございません。 上記2つ実施しましたが、解消できませんでした。 自分なりに考えてみましたが、windows10のubuntuで稼働しているのにも関わらず、ChromeDriverManagerがlinux64を落としてきているからではないかと推測しています。(--headlessで動くのは依然謎ですが…) そちらで今引き続き対応探っています。 >[WDM] - Driver [/root/.wdm/drivers/chromedriver/linux64/87.0.4280.20/chromedriver] found in cache
sg_mm

2020/12/11 14:48

長期にお付き合いいただき非常にありがとうございます。 ChromeDriverManagerではなく、以下のコードで手動でPathを指定するよう変更してみたところ、 別のエラーになったので、ちょっと問題が違う方向に進みそうなので深堀はやめておきたいと思います。 (/etc/hostsに127.0.0.1 localhostはコメントアウトされておらず設定されています) driver = webdriver.Chrome('/mnt/c/workspace/driver/chromedriver.exe') ---- File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__ self.service.start() File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.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 /mnt/c/workspace/driver/chromedriver.exe
Takeshi_Ueda

2020/12/14 08:08

ubuntu上でdriver指定してるわけでなく。。Windows上のdriver使ってるんですね。 WSL2上のubuntuなのは理解しましたが。。 最初からその旨記載されてないとubuntuでdriver指定していると思います。 ubuntuからWindowsのexeは実行できるんでしたっけ? そもそもがおかしいと思いますよ。(これ以上は、システム構成を記載していただかないと答えようないです)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問