我已经使用pip3 install下载了lxml和beautifulsoup4,两者都成功了。我尝试过卸载和安装多次,但没有任何工作。我的beautifulsoup4工作正常,但lxml自我下载以来没有工作过一次。
我的脚本以以下导入语句开始,这些语句都可以正常工作:
import requests
from urllib.request import urlopen
from bs4 import BeautifulSoup
import lxml
然后开始代码:
base_url = 'http://www.nytimes.com'
r = requests.get(base_url)
soup = BeautifulSoup(r.text, "lxml")
我的错误信息如下:
Mathews-MacBook-Pro:desktop MatLefkofsky$ python3 Homework2_Final_Turnin.py
Traceback (most recent call last):
File "Homework2_Final_Turnin.py", line 16, in <module>
soup = BeautifulSoup(r.text, "lxml")
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bs4/__init__.py", line 165, in __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
如何解决此问题?我一直在关注所有其他堆栈页面,没有任何作用。我在Mac上运行OS X 10.11.5。