SelemiumとChromedriverを利用し、Pythonでスクレイピングをしようとしています。
いったん別のPCでコードを書き、元々実行したかったPCに移して手直ししました。
一通り修正して実行すると、次の様なエラーメッセージが表示されました。
* 種類 <class 'selenium.common.exceptions.StaleElementReferenceException'>
* 内容 Message: stale element reference: element is not attached to the page document
コードは次の様になっています。
Python
1lists = [] 2driver = webdriver.Chrome(r'C:\Users\~\chromedriver.exe') 3URL = "url" 4driver.set_page_load_timeout(20) 5driver.get(URL) 6while True: 7 try: 8 items = driver.find_elements_by_class_name('className') 9 for item in items: 10 lists.append(item.text) 11 if len(driver.find_elements_by_xpath('//*[@id="mainBlock"]/div[2]/div[2]/div/div/div[2]/ul/li[3]/a')) > 0: 12 nextpage = driver.find_element_by_xpath('//*[@id="mainBlock"]/div[2]/div[2]/div/div/div[2]/ul/li[3]/a') 13 nextpage.click() 14 driver.implicitly_wait(10) 15 else: 16 break 17 except Exception as e: 18 print('* 種類', type(e)) 19 print('* 内容', e) 20 break
waitを入れてもエラーが出るため、原因が特定できていない状況です。
ご回答お待ちしています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。