Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser

python 小白,Java程序员闲来无事研究了下python爬虫,在执行如下代码:

import requests
from bs4 import BeautifulSoup
url = 'http://www.weather.com.cn/weather/101230101.shtml'

header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                      'AppleWebKit/537.36 (KHTML, like Gecko) '
                      'Chrome/69.0.3486.0 Safari/537.36'}

response = requests.get(url=url, headers=header)
response.encoding = 'utf-8'
print(response.text)

soup = BeautifulSoup(response.text, "lxml")
print(soup)

遇到了如下问题:

Traceback (most recent call last):
  File "D:/PycharmProjects/WeatherCapture/weatherCN.py", line 13, in <module>
    soup = BeautifulSoup(response.text, "lxml")
  File "D:\PycharmProjects\WeatherCapture\venv\lib\site-packages\bs4\__init__.py", line 208, 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?

在网上搜索到的方法是执行命令:

pip3 install lxml

命令行执行结果
执行没问题。
可是重新执行python依旧报错。
解决办法:
1.点击屏幕右下方的python,选择Interpreter Setting…
在这里插入图片描述
2.在弹出的窗口中点“+
在这里插入图片描述
3.在点击“+”后弹出的新窗体输入框输入“lxml”,之后点击左下角的 Install Package提示在这里插入图片描述
表示已经OK了。
4.关闭弹出窗体,重新执行python代码,已经不报错了。
在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值