刚刚安装了BeautifulSoup Python 3.3.0

时间:2012-10-27 03:23:35

标签: python python-3.x beautifulsoup

有谁知道如何修复它。 我使用的是Mac OS 10.8.2

>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/bs4/__init__.py", line 359
    print soup.prettify()
             ^
SyntaxError: invalid syntax

3 个答案:

答案 0 :(得分:6)

在Python 3中print是一个函数;它应该是:

print(soup.prettify())

正确安装bs4或使用较新版本(如果是错误)。 beautifulsoup4==4.1.3在Python 3.3上运行良好。

答案 1 :(得分:2)

https://github.com/il-vladislav/BeautifulSoup4只需将其复制到Lib目录即可。它是Python 3.3的固定版本

答案 2 :(得分:0)

Beautiful Soup 4适用于Python 2(2.6+)和Python 3。

Beautiful Soup是根据MIT许可证获得许可的,因此您也可以下载tarball,将bs4 /目录放入几乎任何Python应用程序(或您的库路径)并立即开始使用它。如果您想在Python 3下执行此操作,则需要使用2to3手动转换代码。

http://www.crummy.com/software/BeautifulSoup/

使用 python ../python33/Tools/Script/2to3.py -w beautifulsoup4-4.3.2 没关系