 <p>Create a function which tries to find your text, and instead of raising an error, returns a string error message.</p> <pre><code>def safe_find(element, text, error_message): try: return element.find(text=re.compile(text)) except: return error_message </code></pre> <p>Then you can use this function to retrieve possibly missing fields, without any inline try-except clauses.</p> <pre><code>address = safe_find(house, '[0-9]{4}[ ]?[azAZ]{2}', "ERR No Address") </code></pre> <hr> <p>Edit: you could make the function slightly more extensible, accepting any parameter that <code>find</code> could take:</p> <pre><code>def safe_find(element, error_message, *args, **kargs): try: return element.find(*args, **kargs) except: return error_message safe_find(house, "ERR No Address", text=re.compile('[0-9]{4}[ ]?[azAZ]{2}')) safe_find(house, "ERR no street", "a", class_='object-street') safe_find(house, "ERR no street", "a", class_='object-street') safe_find(house, "ERR no number", 'span', title=re.compile('Number of')) safe_find(house, "ERR no WaitingFor", "span", title="WaitingFor") </code></pre> <p>... But you wouldn't be able to use this to access any attributes, such as <code>text</code> or <code>attrs['href']</code>.</p> <hr> <p>Edit edit: you could create a special object that has an error message for all the attributes you might possibly want to access.</p> <pre><code>import collections def safe_find(element, error_message, *args, **kargs): class FakeResult: def __init__(self, err): self.attrs = collections.defaultdict(lambda: err) self.text = err #todo: add other attributes here, like: #self.whatever = err try: return element.find(*args, **kargs) except: return FakeResult(error_message) safe_find(house, "ERR no street", "a", class_='object-street').text safe_find(house, "ERR no street", "a", class_='object-street').attrs['href'] safe_find(house, "ERR no number", 'span', title=re.compile('Number of')).text safe_find(house, "ERR no WaitingFor", "span", title="WaitingFor").text </code></pre> <p>However, this <em>only</em> works if you're going to access the <code>text</code> or <code>attrs</code> attributes. <code>safe_find(house, "ERR No Address", text=re.compile('[0-9]{4}[ ]?[azAZ]{2}'))</code> with no <code>.text</code> or <code>.attrs["stuff"]</code> following it will give you a FakeResult instance instead of a string.</p>