运行下面代码:
page = requests.get(url) #url是一个网址
soup = BeautifulSoup(page.text, 'lxml')
报错:
File "<ipython-input-324-9cb4fa68f64f>", line 1, in <module>
BeautifulSoup(page.text, 'lxml')
File "...\lib\site-packages\bs4\__init__.py", line 245, in __init__ % ",".join(features))
FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
解决方法:
soup = BeautifulSoup(page.text, 'lxml') 改为 soup = BeautifulSoup(page.text, "html.parser")
本来先在anaconda安装了lxml,能在spyder import成功,但是再次运行代码仍然报一养的错,应该是我没有安装成功,抱着试试的心态换成"html.parser"能运行。但是lxml为啥还会报错仍然有待探究。