为了账号安全,请及时绑定邮箱和手机立即绑定

python3.6 出现ImportError: cannot import name 'BeautifulSoup' 错误 求助

from bs4 import BeautifulSoup


html_doc = """

<html><head><title>The Dormouse's story</title></head>


<p class="title"><b>The Dormouse's story</b></p>


<p class="story">Once upon a time there were three little sisters; and their names were

<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,

<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and

<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;

and they lived at the bottom of a well.</p>


<p class="story">...</p>

"""

soup = BeautifulSoup(html_doc,"html.parser",from_encoding="utf-8")


print("获取所有连接")


links =soup.find_all('a')


for link in links:


        print (link.name,link['href'],link.get_text())


正在回答

3 回答

楼主,我研究了一个晚上,from bs4 import BeautifulSoup报错No module named 'bs4'问题,琢磨了一个方法。


首先,我使用的IDE是PyCharm Python版本3.6,在file选项中选择settings选项点进去

http://img1.sycdn.imooc.com//5a6886dd000159e102870551.jpg

然后选择Project Interpreter

http://img1.sycdn.imooc.com//5a6887140001216b10410724.jpg

双击pip点进去

http://img1.sycdn.imooc.com//5a6887460001804410410724.jpg

搜索ps4点击   然后点击Install Package等会即可

应该有用,但是我也是才学没多久,方法也是在网上还是群里面看大佬们看出来的,希望对楼主有帮助。


0 回复 有任何疑惑可以回复我~
#1

hi_hello_world 提问者

非常感谢!
2018-02-01 回复 有任何疑惑可以回复我~

https://img1.sycdn.imooc.com//5ce50c600001ac5313040811.jpg

C:\Users\lenovo\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/lenovo/PycharmProjects/untitled/beautifulsoup.py

Traceback (most recent call last):

  File "C:/Users/lenovo/PycharmProjects/untitled/beautifulsoup.py", line 1, in <module>

    from bs4 import beautifulsoup

ImportError: cannot import name 'beautifulsoup'


Process finished with exit code 1

应如何处理?

0 回复 有任何疑惑可以回复我~

先确定是否安装了BeautifulSoup

0 回复 有任何疑惑可以回复我~
#1

hi_hello_world 提问者

这个已经装了
2017-06-20 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Python开发简单爬虫
  • 参与学习       227670    人
  • 解答问题       1219    个

本教程带您解开python爬虫这门神奇技术的面纱

进入课程

python3.6 出现ImportError: cannot import name 'BeautifulSoup' 错误 求助

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信