python – 无需安装即可使用/导入Beautiful Soup 4

正如Beautiful Soup文档所说:

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.

这正是我想要的,以及我所做的……直到在我的代码中使用它.我不知道如何导入Beautiful Soup 4.与v3不同,没有独立的BeautifulSoup.py,只是带有一堆python脚本的bs4目录.当你在项目中有源代码时,有没有人有一个如何使用Beautiful Soup 4的例子?

最佳答案 那一堆“python脚本”被称为
python package;那里应该有一个__init__.py文件.它们共同形成一个连贯的整体,一组命名空间的模块.

您可以从bs4包中导入BeautifulSoup类:

from bs4 import BeautifulSoup

documentation for more info.

点赞