[F] Fix stale element reference exception
This commit is contained in:
+10
-3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user