这是我的文件夹树:
script/
main.py
dependencies/
bs4/
...
requests/
...
以下是我从main.py
导入模块的方法:
import dependencies.requests as requests
import dependencies.bs4 as bs4
该脚本似乎工作正常,但我无法弄清楚如何将qtml解析器添加到dependencies\
与BeautifulSoup一起工作。所以目前在main.py
我发出以下GET请求:
response = requests.get(url)
然后尝试解析它:
parsed_html = bs4.BeautifulSoup(response.content, "lxml")
然后我得到以下异常:
File "C:\Users\usr\Desktop\script\dependencies\bs4\__init__.py", line 165, in __init__
% ",".join(features))
dependencies.bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
任何帮助将非常感激。
此外,默认的"html.parser"
抛出相同的异常。
您应该将PYTHONPATH
扩展到安装lxml或html.parser的文件夹。有了这个,“python”将知道在哪个特定位置搜索您的包。
在任何一种情况下,您都在创建具有依赖关系的文件夹结构,因为有一些工具,例如virtualenv。