Using/importing Beautiful Soup 4 without installation

余生长醉 提交于 2020-01-04 01:53:07

问题


As the Beautiful Soup documentation says:

If all else fails, the license for Beautiful Soup allows you to package the entire library with your application. You can download the tarball, copy its bs4 directory into your application’s codebase, and use Beautiful Soup without installing it at all.

This is exactly what I want, and what I've done... up to the point of using it in my code. I don't know how to import Beautiful Soup 4. Unlike v3, there's no standalone BeautifulSoup.py, just that bs4 directory with a bunch of python scripts. Does anyone have an example of how to use Beautiful Soup 4 when you have the source code in your project?


回答1:


That 'bunch of python scripts' is called a python package; there should be a __init__.py file in there somewhere. Together they form a coherent whole, a namespaced set of modules.

You can just import the BeautifulSoup class from the bs4 package:

from bs4 import BeautifulSoup

See the documentation for more info.



来源:https://stackoverflow.com/questions/11002846/using-importing-beautiful-soup-4-without-installation

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