BeautifulSoup and Requests Module NoneType Error

2343 views python
-1

I've been experimenting with the requests and the bs4 module for a couple of days now. I wanted to make a simple program similar to the 'I'm Feeling Lucky' from google.

Here's my code:

import requests, bs4, webbrowser

source=requests.get('https://www.google.com/search?q=facebook').text

exsoup=bs4.BeautifulSoup(source, 'lxml')
# <cite class="iUh30">https://www.facebook.com/</cite>
match=exsoup.find('cite', class_='iUh30')

print(match.text)

But when I run this I get the following error:

    print(match.text)
AttributeError: 'NoneType' object has no attribute 'text'

How can I make this work?

answered question

1 Answer

3

You can use the following code instead of exsoup.find('cite', class_='iUh30')

exsoup.find_all('cite',{'class': 'iUh30'})

posted this

Have an answer?

JD

Please login first before posting an answer.