BeautifulSoup Web Scraping Tutorial coding problem

I’ve been trying to get through this tutorial:

and I’m stuck on importing BeautifulSoup

My Code:

When I put in the next line of code in the tutorial:
soup = BeautifulSoup(page.content, ‘html.parser’) it just comes up with a NameError.

How do I import BeautifulSoup? I’ve tried from bs4 import BeautifulSoup and that doesn’t work. I’ve tried other tutorials on this and I always get stuck on this and I’ve never been able to figure out what I’m doing wrong.

NameError means the object is not defined in the scope you’re working in.
Is the problem with BeautifulSoup, or page.content?
If BeautifulSoup, did you import properly without ImportError?
If import was successful, there should not be NameError, if import was unsuccessful, the code should have broken way earlier and would not even reach NameError.

1 Like

I’m assuming I didn’t import BeautifulSoup properly but I’m not sure what the proper way is. All the ways I tried didn’t work.

It will be helpful if you could confirm this:

Did you see any ImportError, yes/no?

It is difficult to help with the insufficient information currently.
NameError must be complaining about a particular object. What is that object that is causing NameError? Pasting the sentence containing the error together with your question will give others more context, because any same error can be caused by many different things. Sometimes, even pasting the line in your code where it happens is useful too because others can see what you did/did not do a few lines before/after.

We can fix things by reading the error message and understanding what it’s complaining about. In this case, some variable is not recognized, so we have to make it recognized.
Sometimes it‘s a typo that causes this.

I managed to get BeautifulSoup to import. Now I’m getting an Attribute Error. I’m following the tutorial but I’m obviously missing something.
Here is my code:

from bs4 import BeautifulSoup

from bs4 import BeautifulSoup

In [8]:

import requests

In [11]:



<Response [200]>

In [23]:

soup=BeautifulSoup(“page.content”, ‘html.parser’)

In [30]:



In [35]:


In [36]:


--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in ----> 1 seven_day.find_all(class_=“tombstone-container”) AttributeError: ‘NoneType’ object has no attribute ‘find_all’