install BeautifulSoup

有些话、适合烂在心里 提交于 2019-12-29 08:17:09

问题


im running python 3.1.2 on my ubuntu 10.04

which version of BeautifulSoup i need to install and how?

i already download version 3.2 and run sudo python3 setup.py install but doesnt works

thnx

EDIT : The error i get is :

>>> import BeautifulSoup
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "BeautifulSoup.py", line 448
    raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr)
                        ^
SyntaxError: invalid syntax
>>> 

回答1:


The only series of BeautifulSoup which works with Python 3 is 3.1 However the author has abandoned it and will not release updates. You can read more about the problems here.

UPDATE: This is no longer true, BeautifulSoup 4 works on Python 3. You can install it with pip install beautifulsoup4.

pip install BeautifulSoup will install version 3.




回答2:


I followed these steps to install beautifulsoup4 for HTML parsing.

  • Download the Beautiful Soup 4 source tarball and install it with

    $ python3 setup.py install
    
  • After that enter your python3 console

    $ import bs4
    $ from bs4 import BeautifulSoup
    

The first statement will work while the second will fail. You have to change BeautifulSoup module into python3 format with the help of this command.

$ 2to3 -w bs4

3 After that you can run the test again, and everything will work fine.




回答3:


Try beautifulsoup4. It works for both Python 2.x and Python 3.x.

Then just try with:

from bs4 import BeautifulSoup


来源:https://stackoverflow.com/questions/5050596/install-beautifulsoup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!