gpt4 book ai didi

python - 名称错误 : name 'bs4' is not defined

转载 作者:行者123 更新时间:2023-12-05 08:51:59 30 4
gpt4 key购买 nike

当我运行代码时:

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 有定义吗?还是不是?

最佳答案

from bs4 import BeautifulSoup 更改为 import bs4

关于python - 名称错误 : name 'bs4' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57883671/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com