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

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

新規登録して質問してみよう
ただいま回答率
85.48%
スクレイピング

スクレイピングとは、公開されているWebサイトからページ内の情報を抽出する技術です。

Jupyter

Jupyter (旧IPython notebook)は、Notebook形式でドキュメント作成し、プログラムの記述・実行、その実行結果を記録するツールです。メモの作成や保存、共有、確認などもブラウザ上で行うことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

selenium

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

Q&A

0回答

1808閲覧

seleniumでスクレイピング実行したい

RHira

総合スコア0

スクレイピング

スクレイピングとは、公開されているWebサイトからページ内の情報を抽出する技術です。

Jupyter

Jupyter (旧IPython notebook)は、Notebook形式でドキュメント作成し、プログラムの記述・実行、その実行結果を記録するツールです。メモの作成や保存、共有、確認などもブラウザ上で行うことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

selenium

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

0グッド

0クリップ

投稿2021/10/17 01:12

編集2021/10/17 05:15

したいこと

研究用に使うために、水文水質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>

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

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

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

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

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

meg_

2021/10/17 02:57

Dockerイメージの構築は済んでいますか?
RHira

2021/10/17 03:31

できているのかわからないので、Docker Imageの詳細を追記しました ご確認いただければ幸いです
meg_

2021/10/17 05:05

options.addArguments("--no-sandbox")を追加すると上手くいくかもしれません。
RHira

2021/10/17 05:16

足してみたのですが、変わらずcrashでした… 申し訳ないです…
meg_

2021/10/17 06:38

https://github.com/SeleniumHQ/docker-selenium/tree/selenium-3 に下記記述がありました。 > $ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:3.141.59-20210929 > #OR > $ docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome:3.141.59-20210929 > This is a known workaround to avoid the browser crashing inside a docker container, here are the documented issues for Chrome and Firefox. The shm size of 2gb is arbitrary but known to work well, your specific use case might need a different value, it is recommended to tune this value according to your needs. Along the examples -v /dev/shm:/dev/shm will be used, but both are known to work. 参考になるでしょうか?
RHira

2021/10/18 03:47

ありがとうございます 後学のための解決メモですが $ docker ps で動いているコンテナIDを出して、 $ docker stop "ID" でストップ。 $ docker run -d -p 4444:4444 --shm-size=10g selenium/standalone-chrome:3.141.59-20210929 で再起動したところ、その後の動作もすべてうまくいきました なお、私のPCはメモリがなぜか128GBも積んであるので、10GBも遠慮なく割り振れた形になります。 既にナレッジが出ていた内容にも丁寧にご対応いただきありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問