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

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

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

Beautiful Soupは、Pythonのライブラリの一つ。スクレイピングに特化しています。HTMLデータの構文の解析を行うために、HTMLタグ/CSSのセレクタで抽出する部分を指定することが可能です。

Python 3.x

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

Q&A

解決済

1回答

2630閲覧

webページにログインして表を取り出したいです.ログインする際のモジュールにエラーが発生します.

maro

総合スコア13

Beautiful Soup

Beautiful Soupは、Pythonのライブラリの一つ。スクレイピングに特化しています。HTMLデータの構文の解析を行うために、HTMLタグ/CSSのセレクタで抽出する部分を指定することが可能です。

Python 3.x

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

0グッド

1クリップ

投稿2022/12/18 06:51

前提

webスプレイピングでログインする必要なページに入って表を取得しようと思っています.
そこで,エラーが生じます.
また,google colabで実装しています.

実現したいこと

  • ログインする必要のあるwebページにログインする.

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

<ipython-input-57-0aec536408f0>:25: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(executable_path='/content/chromedriver.exe', chrome_options=options) <ipython-input-57-0aec536408f0>:25: DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome(executable_path='/content/chromedriver.exe', chrome_options=options) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-57-0aec536408f0> in <module> 23 # Chromeを起動 24 #driver = webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', chrome_options=options) ---> 25 driver = webdriver.Chrome(executable_path='/content/chromedriver.exe', chrome_options=options) 26 27 # ログインページを開く 3 frames /usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self) 115 def assert_process_still_running(self) -> None: 116 """Check if the underlying process is still running.""" --> 117 return_code = self.process.poll() 118 if return_code: 119 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}") AttributeError: 'Service' object has no attribute 'process'

該当のソースコード

python

1# coding: UTF-8 2from time import sleep 3from bs4 import BeautifulSoup 4from selenium import webdriver 5from selenium.webdriver.chrome.options import Options 6from selenium.webdriver.common.keys import Keys 7import service 8 9 10if __name__ == '__main__': 11 12# URL関連 13 url = "https://maonline.jp/db/database" 14 login = "***.ac.jp" 15 password = "pwd" 16 17 # ヘッドレスモードの設定。 18 # True => ブラウザを描写しない。 19 # False => ブラウザを描写する。 20 options = Options() 21 options.add_argument('--headless') 22 23 # Chromeを起動 24 #driver = webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', chrome_options=options) 25 driver = webdriver.Chrome(executable_path='/content/chromedriver.exe', chrome_options=options) 26 27 # ログインページを開く 28 driver.get(url) 29 30""" 31 # ログオン処理 32 # ユーザー名入力 33 driver.find_element_by_id(username).send_keys(login) 34 driver.find_element_by_id('btnNext').send_keys(Keys.ENTER) 35 36 # ブラウザの描写が完了させるためにsleep 37 sleep(10) 38 39 # パスワード入力 40 driver.find_element_by_id(passwd).send_keys(password) 41 driver.find_element_by_id(btnSubmit).send_keys(Keys.ENTER) 42 43 # soupオブジェクトを作成 44 soup = BeautifulSoup(driver.page_source, lxml) 45 46 # ログイン後のトップページのソースを表示 47 print(soup) 48 49 # ドライバーをクローズ 50 driver.close() 51 driver.quit() 52 53"""

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

webdriver.Chromeでエラーをはいているのですが,原因が分かりません.指定したパスが適切でない可能性も考えました.colab上のファイルにカーソルを合わせて右クリックするとパスをコピーすることができます.そのパスを指定しているので,適切だとは思うのですが、、、
有識者の方,お教えいただければ幸いです.

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

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

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

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

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

meg_

2022/12/18 07:34

下記コマンドを実行したときに chromedriver.exe は表示されますか? !ls /content/
guest

回答1

0

ベストアンサー

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

エラーログにあるとおり、現在 executable_path を直接 webdriver.Chrome() の引数に渡すのは非推奨です。

そのため、

AttributeError: 'Service' object has no attribute 'process'

というエラーが送出されていると思われます。

現在、推奨されている方法は、Servie クラスを利用して引数を渡す方法です。

python

1from selenium import webdriver 2from selenium.webdriver.chrome.service import Service 3 4 5url = "https://maonline.jp/db/database" 6 7chrome_options = webdriver.ChromeOptions() 8 9chrome_options.add_argument("--headless") 10 11service = Service(executable_path="/content/chromedriver.exe") 12driver = webdriver.Chrome(service=service, options=chrome_options) 13 14driver.get(url)

加えて、options にも非推奨の警告が出ているので、現在推奨されている webdriver.ChromeOptions() クラスを利用しています。

これでも、動かないようであれば恐らく chromedriver.exe のパスが間違っているか存在していないかのどちらかだと思います。

投稿2022/12/23 13:35

編集2022/12/23 13:39
Demerara

総合スコア397

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問