我曾尝试在mac os终端上运行python程序,但在成功安装Beautifulsoup4后,我不断收到以下反馈

我曾尝试在mac os终端上运行python程序,但在成功安装Beautifulsoup4后,我不断收到以下反馈,python,macos,terminal,beautifulsoup,Python,Macos,Terminal,Beautifulsoup,这是我试图运行的代码,下面是我从终端得到的响应: import urllib from Beautifulsoup import* url = raw_input('Enter - ') html = urllib.urlopen(url).read() soup = Beautifulsoup(html) #Retrieve a list of the anchor tags #Each tag is like a dictionary of HTML attributes tags

这是我试图运行的代码,下面是我从终端得到的响应:

import urllib
from Beautifulsoup import*

url = raw_input('Enter - ')

html = urllib.urlopen(url).read()
soup = Beautifulsoup(html)

#Retrieve a list of the anchor tags
#Each tag is like a dictionary of HTML attributes

tags = soup('a')

for tag in tags:
    print tag.get('href', None)

请帮我检查错误

您的导入错误,请将
从Beautifulsoup导入*
更改为:

MacBook-Pro-3:documents frankline$ sudo pip install Beautifulsoup4
The directory '/Users/frankline/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/frankline/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting Beautifulsoup4
  Downloading beautifulsoup4-4.5.3-py2-none-any.whl (85kB)
    100% |████████████████████████████████| 92kB 151kB/s 
Installing collected packages: Beautifulsoup4
Successfully installed Beautifulsoup4-4.5.3
您可能正在查找BeautifulSoup3的文档。如果是这样的话,您应该知道BeautifulSoup3不再被开发,而BeautifulSoup4被推荐用于所有新项目。如果您想了解靓汤3和靓汤4之间的区别,请参阅

阅读bs4库

请阅读:

从bs4导入美化组
soup=BeautifulSoup(打开(“index.html”))
汤=美化组(“数据”)

每当遇到导入错误时,请首先尝试在python控制台中导入

请使用此进口声明使用BeautifulSoup4

from bs4 import BeautifulSoup

soup = BeautifulSoup(open("index.html"))

soup = BeautifulSoup("<html>data</html>")

我尝试了推荐,但仍然得到以下错误代码。回溯(最后一次调用):文件“/parsing_html.py”,第2行,从bs4导入Beautifulsoup导入错误:无法导入名称Beautifulsoup@user3741351你确定你把它安装在正确的地方了吗?你的电脑里有几种python版本吗?有。让机器人python 2和python 3。当我在python3中试用它时,会出现以下错误:MacBook-Pro-3:documents frankline$python3 parsing_html.py文件“parsing_html.py”,第15行print tag.get('href',None)^SyntaxError:无效语法
from bs4 import BeautifulSoup
from bs4 import BeautifulSoup

soup = BeautifulSoup(open("index.html"))

soup = BeautifulSoup("<html>data</html>")
from bs4 import BeautifulSoup