|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import bs4
import 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的时候一直报这个错,百度了也解决不了,有大佬能解决一下吗
请输入搜索内容: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?
本帖最后由 Twilight6 于 2020-7-4 08:56 编辑
安装下解析器,你使用 lxml 解析器之前肯定要先安装 lxml 模块:
python -m pip install lxml -i https://pypi.tuna.tsinghua.edu.cn/simple
代码没问题,运行不报错:
|
|