0

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)

Thanks

0

1 Answer 1

1
bbb = re.compile('First listed')
next_s = soup.find(text=bbb)
if next_s is not None:
    # node exists
else:
    # node does not exists
Sign up to request clarification or add additional context in comments.

7 Comments

thanks what do i put under the 'if next_s is not None:'?
depends on the logic of your script. if you have a list of links, and iterate over it in for loop then use continue, for next iteration.
I'm pretty new to coding so i'm not too sure what that means. It doesnt have many links in the crawler, most of my code is below: where would I put the for and continue statements? Def get_single_item_data(item_url): source_code = requests.get(item_url) plain_text = source_code.text soup = BeautifulSoup(plain_text) bbb = re.compile('First listed') next_s = soup.find(text=bbb) writer.writerow([address, price, Bedroom, Description, Sold, next_s, next_ss])
can you post the example of HTML for parsing?
The below is the beginning of the code: I posted the rest of the code above. Thanks for your help. url = 'zoopla.co.uk/for-sale/property/manchester/…' source_code = requests.get(url) plain_text = source_code.text soup = BeautifulSoup(plain_text) for link in soup.findAll('a', {'class': 'listing-results-price text-price'}): href = "zoopla.co.uk" + link.get('href') get_single_item_data(href)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.