Django BeautifulSoup FeatureNotFound

时间:2014-09-06 01:41:43

标签: python django beautifulsoup

当尝试使用Django使用BeautifulSoup刮取某些内容时,它会返回:

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

它停止的代码行是:

urlContent = urllib2.urlopen(url).read()    
soup = BeautifulSoup(''.join(urlContent))

我尝试了不同的导入方式:

from bs4 import BeautifulSoup
import BeautifulSoup
etc, etc. 

我在树桩上,我不知道这是什么或为什么。在.py中测试它时工作正常,所以我只能假设它是Django。任何已知的修复/解决方法?

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\django\bin\project\Main\functions.py" in mangasee
  44.   soup = BeautifulSoup(''.join(urlContent))
File "D:\django\bin\project\Main\bs4\__init__.py" in __init__
  152.                     % ",".join(features))

Exception Type: FeatureNotFound at /moderator/
Exception Value: Couldn't find a tree builder with the features you requested: html,fast. Do you need to install a parser library?

1 个答案:

答案 0 :(得分:1)

从错误信息中可以清楚地看出,Python找不到HTML解析器,这是bs工作所必需的。 BeautifulSoup支持许多解析器,例如Python标准库中的HTML解析器。从您提供的代码中我看不出为什么找不到解析器。有时它是因为bs的版本与您正在使用的Python版本不匹配。有关详细信息,请参阅此网站http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-beautiful-soup