NameError: name 'bs4' is not defined
NameError: name 'bs4' is not defined
当我运行代码:
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)
我收到以下错误:
File "c:\users\kerss\diet\scrape.py", line 8, in <module>
soup = bs4.BeautifulSoup(html, 'html.parser')
NameError: name 'bs4' is not defined
但是bs4有定义吗?还是不是?
只需使用soup = BeautifulSoup(html, 'html.parser')
将from bs4 import BeautifulSoup
更改为import bs4
当我运行代码:
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)
我收到以下错误:
File "c:\users\kerss\diet\scrape.py", line 8, in <module>
soup = bs4.BeautifulSoup(html, 'html.parser')
NameError: name 'bs4' is not defined
但是bs4有定义吗?还是不是?
只需使用soup = BeautifulSoup(html, 'html.parser')
将from bs4 import BeautifulSoup
更改为import bs4