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

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

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

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

Q&A

解決済

1回答

7661閲覧

Seleniumでchromedriverが機能しない

nukoko

総合スコア1

Python

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

0グッド

0クリップ

投稿2021/10/01 17:13

編集2021/10/02 02:45

前提・実現したいこと

chromeを使ったスクレイピングを行いたいです。
そこで、chromedriverを使おうとしましたが、下記エラーが表示され実行できずにいます。
解決策をご存じの方居られましたらご教示ください。

■「cannot find Chrome binary」
Chromeの実行ファイルを見つけることができていないと考えています。

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

WebDriverException Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15072/1528954596.py in <module>
----> 1 chrome = webdriver.Chrome(ChromeDriverManager().install())
2 driver.get('https://google.com' class="ansi-yellow-intense-fg ansi-bold">)

C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\chrome\webdriver.py in init(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
74
75 try:
---> 76 RemoteWebDriver.init(
77 self,
78 command_executor=ChromeRemoteConnection(

C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\webdriver.py in init(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
155 warnings.warn("Please use FirefoxOptions to set browser profile",
156 DeprecationWarning, stacklevel=2)
--> 157 self.start_session(capabilities, browser_profile)
158 self._switch_to = SwitchTo(self)
159 self._mobile = Mobile(self)

C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\webdriver.py in start_session(self, capabilities, browser_profile)
250 parameters = {"capabilities": w3c_caps,
251 "desiredCapabilities": capabilities}
--> 252 response = self.execute(Command.NEW_SESSION, parameters)
253 if 'sessionId' not in response:
254 response = response['value']

C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
319 response = self.command_executor.execute(driver_command, params)
320 if response:
--> 321 self.error_handler.check_response(response)
322 response['value'] = self._unwrap_value(
323 response.get('value', None))

C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
240 alert_text = value['alert'].get('text')
241 raise exception_class(message, screen, stacktrace, alert_text)
--> 242 raise exception_class(message, screen, stacktrace)
243
244 def _value_or_default(self, obj, key, default):

WebDriverException: Message: unknown error: cannot find Chrome binary

1-1 from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium import webdriver from time import sleep import chromedriver_binary 1-2 chrome = webdriver.Chrome(ChromeDriverManager().install()) driver.get('https://google.com') ### 試したこと 1-2実行結果 ====== WebDriver manager ====== Current google-chrome version is 94.0.4606 Get LATEST driver version for 94.0.4606 Driver [C:\Users\nukok.wdm\drivers\chromedriver\win32\94.0.4606.61\chromedriver.exe] found in cache ### 補足情報(FW/ツールのバージョンなど) OS:windows 64bit Chrome:94.0.4606 install path:C:\Program Files\Google\Chrome\Application ChromeDriver:94.0.4606 実行環境:JupyterLab Python 3.9.5 selenium 3.141.0 ![イメージ説明](c168e5c55e53afa87fdc1e29251b666c.jpeg)

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

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

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

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

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

jbpb0

2021/10/01 21:57

質問の「発生している問題・エラーメッセージ」では ----> 1 chrome = webdriver.Chrome(ChromeDriverManager().install()) でエラーが出てますが、「試したこと」では「1-2」の > chrome = webdriver.Chrome(ChromeDriverManager().install()) でエラーが出てないように見えます (そこに書いてあることだけ見たら) 両者は何が違うのでしょうか? 実行したコードが違うのでしょうか? エラーが出た時のコードは、 1-1 1-2 でしょうか? 違うのでしょうか?
nukoko

2021/10/02 02:37

ありがとうございます。 分かりにくく申し訳ありません。 まず、教えていただいた下記は①のみにしました。 ①「from webdriver_manager.chrome import ChromeDriverManager」 ②「import chromedriver_binary」 下記、実行コマンドとエラー内容になります。 ■実行コマンド chrome = webdriver.Chrome(ChromeDriverManager().install()) ■エラー====== WebDriver manager ====== Current google-chrome version is 94.0.4606 Get LATEST driver version for 94.0.4606 Driver [C:\Users\nukok\.wdm\drivers\chromedriver\win32\94.0.4606.61\chromedriver.exe] found in cache --------------------------------------------------------------------------- WebDriverException Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_12596/1889325130.py in <module> ----> 1 chrome = webdriver.Chrome(ChromeDriverManager().install()) C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\chrome\webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive) 74 75 try: ---> 76 RemoteWebDriver.__init__( 77 self, 78 command_executor=ChromeRemoteConnection( C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options) 155 warnings.warn("Please use FirefoxOptions to set browser profile", 156 DeprecationWarning, stacklevel=2) --> 157 self.start_session(capabilities, browser_profile) 158 self._switch_to = SwitchTo(self) 159 self._mobile = Mobile(self) C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\webdriver.py in start_session(self, capabilities, browser_profile) 250 parameters = {"capabilities": w3c_caps, 251 "desiredCapabilities": capabilities} --> 252 response = self.execute(Command.NEW_SESSION, parameters) 253 if 'sessionId' not in response: 254 response = response['value'] C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params) 319 response = self.command_executor.execute(driver_command, params) 320 if response: --> 321 self.error_handler.check_response(response) 322 response['value'] = self._unwrap_value( 323 response.get('value', None)) C:\JupyterLab\resources\jlab_server\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response) 240 alert_text = value['alert'].get('text') 241 raise exception_class(message, screen, stacktrace, alert_text) --> 242 raise exception_class(message, screen, stacktrace) 243 244 def _value_or_default(self, obj, key, default): WebDriverException: Message: unknown error: cannot find Chrome binary
nukoko

2021/10/02 02:57

実行時のキャプチャを添付しております。 質問内容に記載した内容と被ってしまいますが、chromeも下記にインストールしており、なぜ認識していないのかがわからない状況です。 ■chromeインストール場所 C:\Program Files\Google\Chrome\Application\chrome.exe
jbpb0

2021/10/02 03:34

https://github.com/SeleniumHQ/selenium/issues/8679 に、「C:\Program Files (x86)\…」を探すので、 > install path:C:\Program Files\Google\Chrome\Application にあるChromeを見つけられずに、 > cannot find Chrome binary となる事例が書かれてます ただし、1年前のことなので、さすがに今のバージョンでは直ってると思うのですが
jbpb0

2021/10/02 07:02

以下のようにしてChrome.exeの場所を指定してみたら、どうなりますでしょうか? 下記を追加 from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' 下記を変更 chrome = webdriver.Chrome(ChromeDriverManager().install()) ↓ driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
nukoko

2021/10/02 08:54

jbpb0様 本当にありがとうございます。 無事、chormeを起動することが出来ました!
nukoko

2021/10/03 04:33

jbpb0様 ベストアンサーと解決済みにしたいため、下記内容を回答から再度記載いただくことは可能でしょうか。 よろしくお願いします。 from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' 下記を変更 chrome = webdriver.Chrome(ChromeDriverManager().install()) ↓ driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
guest

回答1

0

ベストアンサー

python

1from webdriver_manager.chrome import ChromeDriverManager

python

1import chromedriver_binary

は、役割が被ってるので、どちらかだけにします (前者がお勧めです)
ChromeDriverを自動更新するライブラリ

 
それでもダメなら、以下のようにしてchrome.exeの場所を指定してみてください (上記は前者の選択が前提)

下記を追加

python

1from selenium.webdriver.chrome.options import Options 2options = Options() 3options.binary_location = 'C:\Program Files\Google\Chrome\Application\chrome.exe'

下記を変更

python

1chrome = webdriver.Chrome(ChromeDriverManager().install())

python

1driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)

投稿2021/10/03 05:16

jbpb0

総合スコア7651

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問