NameError:名称“bs4”未定义

Run*_*ean 2 python urllib beautifulsoup

当我运行代码时:

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)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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

但是bs4定义了?或不?

Ksh*_*ena 5

改成from bs4 import BeautifulSoupimport bs4