したいこと
研究用に使うために、水文水質DBからデータスクレイピングしようとしています。
https://qiita.com/Sampeipei/items/a22bba75acfbd01ac021
上記サイトを参考に構築しています
コード作成と実行はjupyter notebookを用いています
ダウンロード先はI:/suisuiです
発生している問題・エラーメッセージ
WebDriverException Traceback (most recent call last) <ipython-input-9-33a530426e78> in <module> 8 9 # Selenium Server に接続する ---> 10 driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=options.to_capabilities(),options=options,) 11 12 # Selenium 経由でブラウザを操作する ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options) 264 self.file_detector = file_detector or LocalFileDetector() 265 self.start_client() --> 266 self.start_session(capabilities, browser_profile) 267 268 def __repr__(self): ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in start_session(self, capabilities, browser_profile) 355 parameters = {"capabilities": w3c_caps, 356 "desiredCapabilities": capabilities} --> 357 response = self.execute(Command.NEW_SESSION, parameters) 358 if 'sessionId' not in response: 359 response = response['value'] ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params) 416 response = self.command_executor.execute(driver_command, params) 417 if response: --> 418 self.error_handler.check_response(response) 419 response['value'] = self._unwrap_value( 420 response.get('value', None)) ~\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response) 241 alert_text = value['alert'].get('text') 242 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here --> 243 raise exception_class(message, screen, stacktrace) 244 245 def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT: WebDriverException: Message: unknown error: Chrome failed to start: crashed
該当のソースコード
基本的には引用元のもののコピペです
python3
1from bs4 import BeautifulSoup 2from selenium import webdriver 3import pandas as pd 4import datetime 5import matplotlib.pyplot as plt 6import os 7os.chdir('I:/suisui') 8 9from selenium import webdriver 10 11# Chrome のオプションを設定する 12options = webdriver.ChromeOptions() 13options.add_argument('--headless') 14 15# Selenium Server に接続する 16driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=options.to_capabilities(),options=options,) 17 18# Selenium 経由でブラウザを操作する 19driver.get('https://qiita.com') 20print(driver.current_url) 21 22# ブラウザを終了する 23driver.quit()
試したこと
jupyter
1!pip install chromedriver-binary==94.0.4606.61 2!pip install selenium
でchromedriverを入れています。
chrome ver.はVersion 94.0.4606.81 (Official Build) (64-bit)
なので、こちらが最新だと思います。
https://chromedriver.chromium.org/downloads
webdriverは動いているのかと思います
python3
1from selenium import webdriver 2import chromedriver_binary 3driver = webdriver.Chrome()
で,Chromeは起動します。(場所: data:,)
https://qiita.com/kohboh/items/a3e473705f7bf065ba9e
より、ディレクトリ名を¥->/に変更
webdriverをI:/suisuiにも設置
あたりが試した点になります
補足情報
素人なので、追加で必要な情報があればご連絡くださいm(_ _)m
jupyter notebook 6.3.0 <- Anaconda navigaterより
Win10 Pro 21H1 64bit
###追記
①Docker Imageの状態
PowerShell
1PS C:\Users..> docker images 2REPOSITORY TAG IMAGE ID CREATED SIZE 3ID/docker101tutorial latest c7031e4fa799 3 hours ago 28.3MB 4docker101tutorial latest c7031e4fa799 3 hours ago 28.3MB 5alpine/git latest 612b988140be 6 days ago 27.4MB 6selenium/standalone-chrome 3.141.59-xenon da74f3fdcfe2 24 months ago 852MB
②options.add_Arguments("--no-sandbox")追加後
jupyter
1os.chdir('I:/suisui') 2 3from selenium import webdriver 4 5# Chrome のオプションを設定する 6options = webdriver.ChromeOptions() 7options.add_argument('--headless') 8options.add_argument('--no-sandbox') 9 10# Selenium Server に接続する 11driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=options.to_capabilities(),options=options,) 12 13# Selenium 経由でブラウザを操作する 14driver.get('https://qiita.com') 15print(driver.current_url) 16 17# ブラウザを終了する 18driver.quit()
②続き。応答内容
jupyter
1<ipython-input-10-f81577d73398>:11: DeprecationWarning: desired_capabilities has been deprecated, please pass in an Options object with options kwarg 2 driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=options.to_capabilities(),options=options,) 3--------------------------------------------------------------------------- 4WebDriverException Traceback (most recent call last) 5<ipython-input-10-f81577d73398> in <module> 6 9 7 10 # Selenium Server に接続する 8---> 11 driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',desired_capabilities=options.to_capabilities(),options=options,) 9 12 10 13 # Selenium 経由でブラウザを操作する 11 12~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options) 13 264 self.file_detector = file_detector or LocalFileDetector() 14 265 self.start_client() 15--> 266 self.start_session(capabilities, browser_profile) 16 267 17 268 def __repr__(self): 18 19~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in start_session(self, capabilities, browser_profile) 20 355 parameters = {"capabilities": w3c_caps, 21 356 "desiredCapabilities": capabilities} 22--> 357 response = self.execute(Command.NEW_SESSION, parameters) 23 358 if 'sessionId' not in response: 24 359 response = response['value'] 25 26~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params) 27 416 response = self.command_executor.execute(driver_command, params) 28 417 if response: 29--> 418 self.error_handler.check_response(response) 30 419 response['value'] = self._unwrap_value( 31 420 response.get('value', None)) 32 33~\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response) 34 241 alert_text = value['alert'].get('text') 35 242 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here 36--> 243 raise exception_class(message, screen, stacktrace) 37 244 38 245 def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT: 39 40WebDriverException: Message: unknown error: Chrome failed to start: crashed 41 (chrome not reachable) 42 (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) 43Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' 44System info: host: 'f97debeefe29', ip: '172.17.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.16.3-microsoft-standard-WSL2', java.version: '1.8.0_222' 45Driver info: driver.version: unknown 46remote stacktrace: #0 0x5602d26eb7e9 <unknown>
あなたの回答
tips
プレビュー