1. 程式人生 > >【Python】BeautifulSoup匯入lxml報錯

【Python】BeautifulSoup匯入lxml報錯

報錯的程式:

content = bs4.BeautifulSoup(response.content.decode("utf-8"), "lxml")

報錯如下:

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

報錯原因:版本語法錯誤,lxml改成html.parser即可。

修改後程式:

content = bs4.BeautifulSoup(response.content.decode("utf-8"), 'html.parser')