bs4.FeatureNotFound:找不到一棵樹建設者您所要求的功能:LXML。你需要安裝一個解析器庫? [英] bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

查看:21283
本文介紹了bs4.FeatureNotFound:找不到一棵樹建設者您所要求的功能:LXML。你需要安裝一個解析器庫?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

...
soup = BeautifulSoup(html, "lxml")
File "/Library/Python/2.7/site-packages/bs4/__init__.py", line 152, 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?

在我的終端上面的輸出。我在Mac OS 10.7.x.我的Python 2.7.1,并遵循本教程得到美麗的湯和LXML,這既成功安裝并與設在這里一個單獨的測試文件工作。在Python腳本導致此錯誤,我已經包括這一行:
????從pageCrawler進口comparePages
而在pageCrawler文件我已經包括以下兩行:
????從BS4進口BeautifulSoup
????從進口的urllib2的urlopen

The above outputs on my Terminal. I am on Mac OS 10.7.x. I have Python 2.7.1, and followed this tutorial to get Beautiful Soup and lxml, which both installed successfully and work with a separate test file located here. In the Python script that causes this error, I have included this line: from pageCrawler import comparePages And in the pageCrawler file I have included the following two lines: from bs4 import BeautifulSoup from urllib2 import urlopen

在搞清楚的問題是什么,以及它如何可以解決多少會被AP preciated任何幫助。

Any help in figuring out what the problem is and how it can be solved would much be appreciated.

推薦答案

我懷疑,這是相關的BS將用于讀取HTML解析器。他們在這里文件的,但如果你像我一樣(在OSX)你可能會堅持的東西,需要做一些工作:

I have a suspicion that this is related the the parser that BS will use to read the HTML. They document it here but if you're like me (on OSX) you might be stuck with something that requires a bit of work:

您會注意到,在BS4文檔網頁上面,他們指出,在默認情況下BS4將使用內置的HTML解析器Python的。假設你是在OSX,Python中的蘋果??捆綁的版本是2.7.2這是不寬松的字符格式。我打這個同樣的問題,所以我用Python版本升級來解決它。在virtualenv中這樣做將盡量減少對其他項目。

You'll notice that in the BS4 documentation page above, they point out that by default BS4 will use the Python built-in HTML parser. Assuming you are in OSX, the Apple-bundled version of Python is 2.7.2 which is not lenient for character formatting. I hit this same problem, so I upgraded by version of Python to work around it. Doing this in a virtualenv will minimize disruption to other projects.

如果這樣做,聽起來像一個痛苦,你可以切換到LXML解析器:

If doing that sounds like a pain, you can switch over to the LXML parser:

pip install lxml

然后再試試:

soup = BeautifulSoup(html, "lxml")

根據您的情況,這可能是不夠好。我發現這個夠煩人的,以保證升級我的Python版本。使用的virtualenv,可以遷移你的包很容易

這篇關于bs4.FeatureNotFound:找不到一棵樹建設者您所要求的功能:LXML。你需要安裝一個解析器庫?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持IT屋!

查看全文
登錄 關閉
掃碼關注1秒登錄
發送“驗證碼”獲取 | 15天全站免登陸
全免费A级毛片免费看无码播放