beautifulsoup lxml解析器问题
import bs4import urllib.request
import urllib.parse
import re
name=str(input('请输入搜索内容:'))
name=urllib.parse.quote(name)
head={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER'}
req=urllib.request.Request('https://baike.baidu.com/item/{}'.format(name),headers=head)
response=urllib.request.urlopen(req)
html=response.read().decode('utf-8')
soup=bs4.BeautifulSoup(html,'lxml')
print(soup.head)
用bs4的时候一直报这个错,百度了也解决不了,有大佬能解决一下吗{:10_266:}
请输入搜索内容:apple
Traceback (most recent call last):
File "C:\Users\ASUS\Desktop\python\spider\zhautu.py", line 15, in <module>
soup=bs4.BeautifulSoup(html,'lxml')
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-packages\bs4\__init__.py", line 242, in __init__
raise FeatureNotFound(
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? 你安装lxml库了吗? 本帖最后由 Twilight6 于 2020-7-4 08:56 编辑
安装下解析器,你使用 lxml 解析器之前肯定要先安装 lxml 模块:
python -m pip install lxml -i https://pypi.tuna.tsinghua.edu.cn/simple
代码没问题,运行不报错:
用python -m pip install lxml -i https://pypi.tuna.tsinghua.edu.cn/simple安装完lxml后就行了{:10_298:},感谢,不过我之前用 pip install lxml安装过lxml, 不知道为什么一直报错 {:10_298:}
页:
[1]