FeatureNotFound:找不到具有您请求的功能的树生成器:lxml。您需要安装解析器库吗?

2024-06-09 02:18:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着运行这个代码来处理“teks”。它显示了 FeatureNotFound:找不到具有您请求的功能的树生成器:lxml。您需要安装解析器库吗?你知道吗

def proses_teks(teks):
soup = BeautifulSoup(teks, "lxml") 
souped = soup.get_text()
try:
    teks = souped.decode("utf-8-sig").replace(u"\ufffd", "?")
except:
    teks = souped
teks_bersih= re.sub("[^a-zA-Z0-9]", " ",(re.sub(www_pat, '', re.sub(combined_pat, '', teks)).lower()))
teks_bersih= ' '.join([word for word in teks_bersih.split() if word not in stopword_user])
return (" ".join([x for x in tok.tokenize(teks_bersih) if len(x) > 1])).strip()

 teks='''hahaha apakah SAYA ingin pergi pada tanggal 15 bulan februari besok ? tidak karena
hari kemarin @twitter suka main https://www.twitter.com'''

proses_teks(teks)

错误:

    ---------------------------------------------------------------------------
FeatureNotFound                           Traceback (most recent call last)
<ipython-input-83-334183dacf47> in <module>
----> 1 proses_teks(teks)

<ipython-input-81-598b2eb2c340> in proses_teks(teks)
      1 def proses_teks(teks):
----> 2     soup = BeautifulSoup(teks, "lxml")
      3     souped = soup.get_text()
      4     try:
      5         teks = souped.decode("utf-8-sig").replace(u"\ufffd", "?")

c:\users\blabla\appdata\local\programs\python\python36-32\lib\site-packages\bs4\__init__.py in __init__(self, markup, features, builder, parse_only, from_encoding, exclude_encodings, element_classes, **kwargs)
    214                     "Couldn't find a tree builder with the features you "
    215                     "requested: %s. Do you need to install a parser library?"
--> 216                     % ",".join(features))
    217 
    218         # At this point either we have a TreeBuilder instance in

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

我已经读到一些错误,它说我应该改变

soup = BeautifulSoup(teks, "lxml") 

soup = BeautifulSoup(html, "lxml") 

但是错误又出现了,说NameError: name 'html' is not defined

我该怎么办?你知道吗


Tags: inreyou错误lxmlwordfeaturesjoin