How can I from bs4 import BeautifulSoup?

▼魔方 西西 提交于 2020-08-02 07:46:16

问题


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 ?


回答1:


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.




回答2:


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

pip3 install beautifulsoup4



回答3:


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.



来源:https://stackoverflow.com/questions/18831380/how-can-i-from-bs4-import-beautifulsoup

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