Forums

Got AttributeError: 'NoneType' object has no attribute 'text'

HI Please can somebody help me with this code on PythonAnywhere?

import requests
from bs4 import BeautifulSoup
url = 'http://CNN.com'
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'html.parser')
tag = soup.find('title')
print(tag.text)

I got AttributeError: 'NoneType' object has no attribute 'text' Thank you

Hi there,

check the response you're getting from the requests.get? My guess is you're getting a 403 error, because CNN isn't on our whitelist. More info here:

http://help.pythonanywhere.com/pages/403ForbiddenError

Yes, You're right