前提
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上のファイルにカーソルを合わせて右クリックするとパスをコピーすることができます.そのパスを指定しているので,適切だとは思うのですが、、、
有識者の方,お教えいただければ幸いです.
下記コマンドを実行したときに chromedriver.exe は表示されますか?
!ls /content/

回答1件
あなたの回答
tips
プレビュー