【求助】爬虫脚本总提示错误Traceback (most recent call last)
# coding=utf-8
import requests
from bs4 import BeautifulSoup
# 获取html文档
def get_html(url) -> object:
"""get the content of the url"""
response = requests.get(url)
response.encoding = 'utf-8'
return response.text
# 获取笑话
def get_certain_joke(html):
"""get the joke of the html"""
soup = BeautifulSoup(html, 'lxml')
joke_content = soup.select('div.content')[0].get_text()
return joke_content
url_joke = "https://www.qiushibaike.com"
html = get_html(url_joke)
joke_content = get_certain_joke(html)
print(joke_content)
错误提示:
Traceback (most recent call last):
File "C:/Users/cdyoue/PycharmProjects/untitled/JokePaTest.py", line 21, in <module>
joke_content = get_certain_joke(html)
File "C:/Users/cdyoue/PycharmProjects/untitled/JokePaTest.py", line 15, in get_certain_joke
soup = BeautifulSoup(html, 'lxml')
File "C:\Users\cdyoue\AppData\Local\Programs\Python\Python36\lib\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?
Process finished with exit code 1