Detect if beautifulsoup found text on a page or not

Viewed 31
soup.body.findAll(text='No Results Found')

basically I need something that goes like

if soup.body.findAll(text='No Results Found') does find this text:
   print("URL doesn't exist")

really hope this isn't a stupid question but I'm not sure what to look up to find the answer to this if it's been asked already

1 Answers

soup.body.findAll(text='No Results Found') searches for elements that have the exact text 'No Results Found'.

But I think that your problem does not need beautifulsoup at all. To see if the string 'No Results Found' is located on the page you just should try to find your string in the HTML:

import requests

html = requests.get(your_url)
if 'No Results Found' in html:
    print("URL doesn't exist")
Related