Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

python - install BeautifulSoup

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
>>> 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...