Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'bs4' is not defined

When I run the code:

import requests
from bs4 import BeautifulSoup
import urllib

response = urllib.urlopen('file:///Users/kerss/diet/sesame_seeds.html')
html = response.read()
soup = bs4.BeautifulSoup(html, 'html.parser')

span = soup.find("span", id="NUTRIENT_0")
print(span.text)

I get the following error:

  File "c:\users\kerss\diet\scrape.py", line 8, in <module>
    soup = bs4.BeautifulSoup(html, 'html.parser')
NameError: name 'bs4' is not defined

but bs4 is defined? or not?

like image 391
Runner Bean Avatar asked Nov 22 '25 03:11

Runner Bean


1 Answers

Change from bs4 import BeautifulSoup to import bs4

like image 77
Kshitij Saxena Avatar answered Nov 24 '25 20:11

Kshitij Saxena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!