Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I from bs4 import BeautifulSoup?

This code:

from bs4 import BeautifulSoup  

Doesn't work, and gives this error :

raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__,attr)    
                    ^
SyntaxError: invalid syntax    

What should i do ?

like image 752
Mohammad Rahmani Avatar asked Sep 16 '13 15:09

Mohammad Rahmani


3 Answers

You should be using pip to install, so you can simply do

pip install beautifulsoup4

That will install the latest BS4, which is 4.3.1 as of 2013-08-15. It supports Python 3.

like image 194
Jordan Avatar answered Nov 08 '22 03:11

Jordan


Also, if you are using python3, you should use:

pip3 install beautifulsoup4
like image 29
tonhozi Avatar answered Nov 08 '22 05:11

tonhozi


For Windows... Go to start menu type cmd right click on cmd icon click run as administrator then type pip install beautifulsoup4.

It likely will fail to install correctly if you fail to do the above step as even though your windows user is an admin account it does not run all apps as administrator.

Notice the difference if you simply just open cmd without the run as admin.

Remember also when using it like so...

from bs4 import beautifulsoup4

Will not work as it is not correctly formatted.

from bs4 import BeautifulSoup4

Will work correctly as it is CaseSensitive.

like image 3
Goulouh Anwar Avatar answered Nov 08 '22 04:11

Goulouh Anwar