Я решил отказаться от официального планирования, чтобы получить лучшее приложение. (Пытался получить API, но они отказываются).
Когда я тестирую его на своем компьютере, все работает нормально и ничего не устарело, но когда я нажимаю на веб-скрапинг действий GitHub оно, оно несвежее посередине. Кто-нибудь знает, что может вызвать это?
Другая вещь: когда я хочу удалить больше (примерно через 15/20 минут), один элемент устаревает. Как это предотвратить?
Вот код для отмены курсов:
if course_id not in output:
output[course_id] = {}
output[course_id][name] = {}
course = course_dict[course_id]
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH,'//table[@class="as-content"]/tbody/tr')))
driver.implicitly_wait(0.5)
tables = driver.find_elements(By.XPATH,'//table[@class="as-content"]/tbody/tr')
color = getColor("")
for i in range(1,len(tables),2):
course_name = tables.find_elements(By.XPATH,'./td/table/tbody/tr/td/span')[0].text
print(course_name)
if course_name in course:
course_name, color_ = course[course_name]
color = getColor(color_)
if course_name not in output[course_id][name]:
output[course_id][name][course_name] = []
list_cursus = tables[i+1].find_elements(By.XPATH,'./td/div/table/tbody/tr')
for cursus in list_cursus:
info = cursus.find_elements(By.XPATH,'./td')
driver.implicitly_wait(0.1)
date = info[0].find_element(By.XPATH,'./div').get_attribute("innerHTML").replace(" ", " ")
_time = info[1].get_attribute("innerHTML").replace(" ", " ")
row_date = dateparser.parse(date + ' ' + _time[3:8])
if row_date != None:
start = row_date.strftime("%Y-%m-%dT%H:%M:%S")
end = dateparser.parse(date + ' ' + _time[10:17]).strftime("%Y-%m-%dT%H:%M:%S")
teacher = info[3].get_attribute("innerHTML").replace(" ", " ")
room = info[4].get_attribute("innerHTML").replace(" ", " ")
title = course_name + '\n' + teacher + '\n' + room
output[course_id][name][course_name].append({'title':title,'start':start,'end':end, 'color': color})
Я пытался отложить больше, как говорилось на многих других форумах, но это не сработало. Я также пытался сменить драйвер с Chrome на Firefox.
Вот исключение:
Traceback (most recent call last):
File "/home/runner/work/NovaPlanning/NovaPlanning/scraping/scraper.py", line 130, in
get_information(driver,"BAB1 INFO", "INFO")
File "/home/runner/work/NovaPlanning/NovaPlanning/scraping/scraper.py", line 101, in get_information
info = cursus.find_elements(By.XPATH,'./td')
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 439, in find_elements
return self._execute(Command.FIND_CHILD_ELEMENTS, {"using": by, "value": value})["value"]
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 395, in _execute
return self._parent.execute(command, params)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute
self.error_handler.check_response(response)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: The element with the reference 88f3af23-5a4b-4963-94ce-27c4de81849d is stale; either its node document is not the active document, or it is no longer connected to the DOM; For documentation on this error, please visit: https://www.selenium.dev/documentation/ ... -exception
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5
StaleElementReferenceError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:725:5
getKnownElement@chrome://remote/content/marionette/json.sys.mjs:401:11
deserializeJSON@chrome://remote/content/marionette/json.sys.mjs:259:20
cloneObject@chrome://remote/content/marionette/json.sys.mjs:59:24
deserializeJSON@chrome://remote/content/marionette/json.sys.mjs:289:16
cloneObject@chrome://remote/content/marionette/json.sys.mjs:59:24
deserializeJSON@chrome://remote/content/marionette/json.sys.mjs:289:16
json.deserialize@chrome://remote/content/marionette/json.sys.mjs:293:10
receiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:73:30
Подробнее здесь: https://stackoverflow.com/questions/789 ... en-testing