What I'm trying to do: I'm essentially running a search procedure with a list of IDs. Those that fail for some reason, I append to a separate list so that I can choose to re-run just those under some different parameters.
How I'm trying to do it:
# Defining the customer ID list and a list for failed searches
customer_IDs = [1,2,3,4,5]
failed_IDs = []
# Looping the search procedure for all IDs in the original list
for customerid in customer_IDs:
try:
search_procedure(customerid)
except:
failed_IDs.append(customerid)
pass
if len(failed_IDs) > 0:
print("There were " + str(len(failed_IDs)) + " customers that were not found")
My expectation was that, once the code failed to find customer 1, for instance, it would resume the loop for the remaining 4 and only then go evaluate how long the list is in the if
statement. However, after the first ID is not found, it goes straight to the if
section.
I have tried to reset the code with both pass
and continue
, and it's still maintaining the same behavior.
Why I know the loop isn't going forward: Essentially because this is an attempt of web scraping with Selenium. I'm automating a task of searching, navigating and downloading for a series of documents using customer IDs. When the first one breaks, it does not proceed to the second one. The reason the search is failing is because I'm currently unable to properly make Selenium switch to the frame where the necessary, final button is. Unfortunately, there is no error message from the code itself to share with you guys.
I've searched around quite extensively and still found nothing quite similar except for the continue/pass statements on the code, which have not helped.
Any tips for a newbie?
Thanks!