0

Can anyone explain to me why am I getting this error message? I have the exact same code in another project but after creating a new venv and install requests, bs4 and html.parser I get this message. I don't understand, at all.

import requests
import bs4 as BeautifulSoup
import html.parser

source = requests.get('https://docs.python.org/3/library/html.parser.html')
soup = BeautifulSoup(source.text, 'html.parser')

print(soup)
c0nfluks
  • 53
  • 5
  • 1
    you should use BeautifulSoup class. But you imported the module as BeautifulSoup. Change the 2nd line. `import bs4 as BeautifulSoup` to `from bs4 import BeautifulSoup` – NavaneethaKrishnan Jun 15 '22 at 20:01

1 Answers1

0

It looks like you just need to change your bs4 import. Try this:


import requests
from bs4 import BeautifulSoup
import html.parser

source = requests.get('https://docs.python.org/3/library/html.parser.html')
soup = BeautifulSoup(source.text, 'html.parser')

print(soup)

To explain what was wrong, basically you were importing the entire bs4 module in as BeautifulSoup, when you actually wanted to import the BeautifulSoup class from the bs4 module.

Jordan
  • 540
  • 4
  • 10