问题
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