Possible Duplicate:
Using BeautifulSoup, how to guard against elements not being found?
I have the following Python error when Using BeautifulSoup to find all options in a page:
for item in soup.find(id="start_dateid").find_all('option'):
AttributeError: 'NoneType' object has no attribute 'find_all'
The problem is when the page do not have id=”start_dateid”, will generate an error: AttributeError: ‘NoneType’ object has no attribute ‘find_all’
How to prevent this error?
Assign your “subsoup” to a variable first: