When I run it, I get an x error after a certain time. I know I got this error because it's at the end of the page. How do I stop the program without receiving this error?
I tried
if newsContents == "NoneType":
break
or
if newsContents == " ":
break
My code is:
while i < 30:
r = requests.get("blabla" + str(i))
source = BeautifulSoup(r.content,"lxml")
i=i+1
newsContents = source.find("div", attrs={"class": "figCaption"})
print(newsContents.text)
print("#"*10)
print(newsContents.text) AttributeError: 'NoneType' object has no attribute 'text'