Answer the question
In order to leave comments, you need to log in
How to catch a server error when parsing?
I wrote a python + selenium parser, everything works as it should, runs through links, collects all the information (with an open browser).
Sometimes, due to the fault of the server, the parser crashes with an error.
The server responds with 502 (Bad gateway).
The parser crashes , the xpath I need was not found (of course, because an unexpected page was loaded)
Question: how to rewrite the script so that when such an error occurs, the parser does not crash, but makes another attempt (for example, refreshing the page helps), is this possible?
Answer the question
In order to leave comments, you need to log in
1. You can open links in new tabs. Make several attempts to open the link in a new tab and check if there is an error. More or less like this:
main_window = driver.current_window_handle
#open the link in a new tab
clickable_element.send_keys(Keys.CONTROL + Keys.RETURN)
#switch to that tab
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
driver.switch_to_window(main_window)
#close the tab
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')
driver.switch_to_window(main_window)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question