None type object has no attribute error in webcrawler Python

I am new to Python so any help would be appreciated. I have a web crawler using beautifulsoup. It works but for the below it returns the error 'None type object has no attribute'. I know it means it has come across a page where there is no entry. How do I stop this error and make it return all the other pages that have entries. Some of the pages in the web crawler have the entry and some are blank.

bbb = re.compile('First listed')
    next_s = soup.find(text=bbb).parent.parent.get_text(strip=True)


1 answer

  • answered 2017-06-17 17:53 Linch

    bbb = re.compile('First listed')
    next_s = soup.find(text=bbb)
    if next_s is not None:
        # node exists
        # node does not exists