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

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

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

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

selenium

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

Q&A

解決済

1回答

1622閲覧

Python、Seleniumでchromeを操作したい!

tatuya.donnan

総合スコア7

Python

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

selenium

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

0グッド

0クリップ

投稿2021/11/09 06:57

前提・実現したいこと

Seleniumを使用してchromeからのWEBスクレイピングをしようとしているのですが、chromeのドライバーの読み込みが上手く出来ません。
いろいろ試してみたのですが解決できなかった為、質問させていただきました。
お力添えお願いします。

使用している環境:
GoogleColaboratory

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

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: executable_path has been deprecated, please pass in a Service object """Entry point for launching an IPython kernel. --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self) 78 stdin=PIPE, ---> 79 creationflags=self.creationflags) 80 except TypeError: 5 frames FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\user\Desktop\test\chromedriver': 'C:\Users\user\Desktop\test\chromedriver' During handling of the above exception, another exception occurred: WebDriverException Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self) 84 raise WebDriverException( 85 "'%s' executable needs to be in PATH. %s" % ( ---> 86 os.path.basename(self.path), self.start_error_message) 87 ) 88 elif err.errno == errno.EACCES: WebDriverException: Message: 'C:\Users\user\Desktop est\chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

該当のソースコード

Python

1driver = webdriver.Chrome('C:\Users\user\Desktop\test\chromedriver')

試したこと

・URLの文字列中エスケープを回避する為一部を\から\へ変更
・他Googleで調べて出てきた内容を多数

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

ここにより詳細な情報を記載してください。

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

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

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

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

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

jbpb0

2021/11/09 07:47

> URLの文字列中エスケープを回避する為一部を\から\\へ変更 一部じゃなくて、全部変更してください
tatuya.donnan

2021/11/10 08:15

返信ありがとうございます。 全て入力しましたが、結果は変わりませんでした。
jbpb0

2021/11/10 08:22

「chromedriver」 ↓ 「chromedriver.exe」 と変えたら、どうでしょうか? > \から\\へ変更 は、全部した上で
tatuya.donnan

2021/11/10 08:43

ありがとうございます。 変更してみましたがやっぱりエラーとなりました。 念のため下記の4つとも実行してみましたが、エラーとなってしまいました。 driver = webdriver.Chrome('C:\\Users\\user\\Desktop\\test\\chromedriver.exe') driver = webdriver.Chrome('C:\\Users\\user\\Desktop\\test\\chromedriver.exe') driver = webdriver.Chrome(r'C:\Users\user\Desktop\test\chromedriver.exe') driver = webdriver.Chrome('C:/Users/user/Desktop/test/chromedriver.exe')
jbpb0

2021/11/10 08:48

コマンドプロンプトで、 dir C:\Users\user\Desktop\test\chromedriver.exe を(上記をコピペして)実行したら、ちゃんと存在してるのでしょうか? 「user」は伏せ字だと思うので、そこだけは実際のに直して、それ以外はコピペで 「user」の実際は、日本語とかスペースとか含んでませんよね? あと、エラーメッセージは、質問に掲載のと違ってると思うので、それを教えてください
tatuya.donnan

2021/11/11 00:17

①コマンドプロンプトで↓をそのまま実行しております。 C:\Users\user>dir C:\Users\user\Desktop\test\chromedriver.exe ドライブ C のボリューム ラベルは OS です ボリューム シリアル番号は D0E4-38EE です C:\Users\user\Desktop\test のディレクトリ 2021/11/09 13:49 11,275,264 chromedriver.exe 1 個のファイル 11,275,264 バイト 0 個のディレクトリ 129,292,910,592 バイトの空き領域 パスも正しいというと考えていますが・・・・ ②エラーメッセージについて driver = webdriver.Chrome('C:/Users/user/Desktop/test/chromedriver.exe') を実行した場合になります。 エラーメッセージ↓ /usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:8: DeprecationWarning: executable_path has been deprecated, please pass in a Service object --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self) 78 stdin=PIPE, ---> 79 creationflags=self.creationflags) 80 except TypeError: 5 frames /usr/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text) 799 errread, errwrite, --> 800 restore_signals, start_new_session) 801 except: /usr/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session) 1550 err_msg += ': ' + repr(err_filename) -> 1551 raise child_exception_type(errno_num, err_msg, err_filename) 1552 raise child_exception_type(err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/user/Desktop/test/chromedriver.exe': 'C:/Users/user/Desktop/test/chromedriver.exe' During handling of the above exception, another exception occurred: WebDriverException Traceback (most recent call last) <ipython-input-25-5bfa445d98b2> in <module>() 6 # driver = webdriver.Chrome('C:\\Users\\user\\Desktop\\test\\chromedriver.exe') 7 # driver = webdriver.Chrome(r'C:\Users\user\Desktop\test\chromedriver.exe') ----> 8 driver = webdriver.Chrome('C:/Users/user/Desktop/test/chromedriver.exe') /usr/local/lib/python3.7/dist-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive) 70 port, options, 71 service_args, desired_capabilities, ---> 72 service_log_path, service, keep_alive) /usr/local/lib/python3.7/dist-packages/selenium/webdriver/chromium/webdriver.py in __init__(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive) 88 89 self.service = service ---> 90 self.service.start() 91 92 try: /usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self) 84 raise WebDriverException( 85 "'%s' executable needs to be in PATH. %s" % ( ---> 86 os.path.basename(self.path), self.start_error_message) 87 ) 88 elif err.errno == errno.EACCES: WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
tatuya.donnan

2021/11/11 01:57

otnさんの回答でWindowsとGoogleコラボでのパスの指定方法が違うとあったので一度そちらも調べてみようと思います。 親身にご対応いただきありがとうございました!
jbpb0

2021/11/11 02:37

> 使用している環境: GoogleColaboratory を見落としてました そういうことかー Google Colabからは、ローカル(質問者さんが直接使ってる)パソコンのストレージは見えないので、ローカルWindowsパソコンのどこかに「chromedriver.exe」を置いて、それを指定してもダメです Google ColabでSeleniumを使う手順を解説してるWebページとか探して、それを参考にしてください
guest

回答1

0

ベストアンサー

\\にするのを何故途中でやめちゃったんでしょう?

Python

1driver = webdriver.Chrome('C:\Users\user\Desktop\test\chromedriver') 2または、 3driver = webdriver.Chrome(r'C:\Users\user\Desktop\test\chromedriver') 4または、 5driver = webdriver.Chrome('C:/Users/user/Desktop/test/chromedriver')

投稿2021/11/09 14:43

otn

総合スコア84808

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

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

tatuya.donnan

2021/11/10 08:18

返信ありがとうございます。 3通り全て実行してみましたが、3つともエラーとなり変化はありませんでした。
otn

2021/11/10 09:15 編集

Windowsにしては、周囲のメッセージが変だと思ったら、WindowsじゃなくてGoogleColaboratoryなんですね。 Windowsの時のコードのコピペでは動かないので、GoogleColaboratoryでの正しいパスを指定しましょう。
tatuya.donnan

2021/11/11 01:55

GoogleColaboratory とパスのしいて方法が違うのですね!ありがとうございます。また調べてみます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問