seleniumを用いて日経新聞の記事タイトルおよび本文をスクレイピングしようとしています。
試しにトヨタ自動車の記事データで試しているのですが2ページ目に行った時に以下のエラー文が出てうまくいきません。
Traceback (most recent call last):
File "selenium_test.py", line 27, in <module>
browser.find_element_by_class_name('nk-navigator-select-all').click()
File "/Users/kojimakazuya/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/Users/kojimakazuya/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/Users/kojimakazuya/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/kojimakazuya/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message:
プログラムは以下になります。
from selenium import webdriver import time from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select # Safariを指定して起動 browser = webdriver.Safari() browser.get('https://t21ipau.nikkei.co.jp/ipauth/auth/auth?sid=1') time.sleep(10) #トヨタ自動車で検索 browser.find_element_by_class_name('nk-home-bundle-search-input').send_keys("トヨタ自動車") browser.find_element_by_class_name('nk-home-bundle-search-button').click() browser.find_element_by_class_name('nk-home-bundle-search-button').click() time.sleep(10) #見出しを表示 browser.find_element_by_name('listUp').click() browser.find_element_by_class_name('nk-popup-ok').click() headline = [] content = [] for i in range(20): time.sleep(5) #全件選択 browser.find_element_by_class_name('nk-navigator-select-all').click() browser.find_element_by_class_name('nk-list-navigator-honbun').click() WebDriverWait(browser, 30).until(EC.element_to_be_clickable((By.CLASS_NAME, "nk-popup-ok"))) browser.find_element_by_class_name('nk-popup-ok').click() time.sleep(5) #タイトルと本文の取得 headlines = browser.find_elements_by_class_name('nk-gv-bodytitle') contents = browser.find_elements_by_css_selector('td.nk-gv-body-view table tbody tr td') for hl in headlines: headline.append(hl.text) for c in contents: content.append(c.text) #次ページへ browser.find_element_by_class_name('nk-navigator-next').click()