Ошибка element is not attached to the page document
Здравствуйте пытаюсь спарсить историю игр с сайта csgo500.io, но столкнулся с проблемой что происходит какая то фигня и то 200 игр в истории, то 249, или же 250, решил взять 180 чтобы везде угодить. Получаю доступ к элементу, парочку раз выводит, а потом ошибка что ссылка на элемент устарела. До указания слипа в 3 сек вообще 1раз выводило и все.
from selenium import webdriver
import time
import csv
driver = webdriver.Chrome()
driver.get("https://csgo500.io/")
time.sleep(10)
driver.find_element_by_xpath('//*[@id="login-content"]/div[3]/div/form/p[1]/label').click()
driver.find_element_by_xpath('//*[@id="login-content"]/div[3]/div/form/p[2]/label').click()
driver.find_element_by_xpath('//*[@id="login-content"]/div[3]/div/form/p[3]/label').click()
time.sleep(15)
hash_game = 0
while True:
last_game = driver.find_element_by_xpath('//*[@id="past-queue-wrapper"]/div[180]').get_attribute('class')
h = driver.find_element_by_xpath('//*[@id="past-queue-wrapper"]/div[180]/div[2]/br[1]')
if hash_game != h:
hash_game = h
print(last_game)
time.sleep(3)
Определение новой игры выполняю по хешу игры.
Вот тут 5 раз правильно вывело а потом ошибка:
DevTools listening on ws://127.0.0.1:53614/devtools/browser/81965873-c264-4a99-892c-d5687556323a
past-1 past-tooltip
past-1 past-tooltip
past-0 past-tooltip
past-0 past-tooltip
past-0 past-tooltip
Traceback (most recent call last):
File "parscsgo500.py", line 21, in <module>
last_game = driver.find_element_by_xpath('//*[@id="past-queue-wrapper"]/div[180]').get_attribute('class')
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 139, in get_attribute
attributeValue = self.parent.execute_script(
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 634, in execute_script
return self.execute(command, {
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=85.0.4183.102