I\'m trying to scrape some information from webpages that are inconsistent about where the info is located. I\'ve got code to handle each of several possibilities; what I want
If each lookup is a separate function, you can store all the functions in a list and then iterate over them one by one.
lookups = [
look_in_first_place,
look_in_second_place,
look_in_third_place
]
info = None
for lookup in lookups:
try:
info = lookup()
# exit the loop on success
break
except AttributeError:
# repeat the loop on failure
continue
# when the loop is finished, check if we found a result or not
if info:
# success
else:
# failure