出现name 'BeautifulSoup' is not defined错误,排查拼写、重装模块仍未解决
解决
name 'BeautifulSoup' is not defined 错误 哈哈,别愁啦!我扫了一眼你的代码,立马就揪出问题根源了——拼写错误!
你看这句代码:
soup=BeatifulSoup(page,"html.parser")
这里的 BeatifulSoup 少了个字母 u!正确的类名应该是 BeautifulSoup 才对。
你之前重新安装模块没用,是因为模块本身安装得没问题,问题全出在你代码里把类名写错了。Python找不到拼写错误的类名,自然就抛出“未定义”的错误啦。
修正后的完整代码如下:
from bs4 import BeautifulSoup from urllib.request import urlopen url="http://finance.naver.com/marketindex" page=urlopen(url) soup=BeautifulSoup(page,"html.parser")
以后写代码可以多留意拼写细节,或者用带自动补全的编辑器,能帮你躲开这类低级小错误哦~
内容的提问来源于stack exchange,提问作者abcshoes
相关产品推荐
相关产品推荐

