[F] Fix stale element reference exception

This commit is contained in:
Hykilpikonna
2022-03-01 17:10:35 -05:00
parent 5f4dd5304f
commit 37f042cc75
4 changed files with 53 additions and 6 deletions
+10 -3
View File
@@ -4,6 +4,7 @@ import time
import traceback
import requests
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
@@ -118,12 +119,18 @@ if __name__ == '__main__':
# parse_page(browser)
# browser.close()
# Refresh indefinitely
while True:
def parse(tries: int = 0):
try:
parse_page(browser)
except StaleElementReferenceException:
if tries < 3:
parse(tries + 1)
except Exception as e:
traceback.print_exc()
time.sleep(5)
# Refresh indefinitely
while True:
time.sleep(3)
parse()
browser.refresh()
time.sleep(2)