将lxml与漂亮的汤结合使用



我很难让lxml与漂亮的汤一起工作。在osx 10.8.4上运行。为了安装lxml,我进行了端口安装py25 lxml,它安装得很好。现在,当我尝试将lxml与Beautiful Soup:一起使用时,我遇到了这个错误

Traceback (most recent call last):
  File "********.py", line 13, in <module>
    soup = BeautifulSoup(urllib2.urlopen(url).read(), 'lxml')
  File "/Users/********/********/bs4/__init__.py", line 155, 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?

不确定这是否是问题的一部分,但我无法导入lxml.etree

有没有其他人使用lxml在osx上处理漂亮的汤?

另外,也许我可以尝试使用不同的html解析器。有人对其他解析器有什么建议吗?

来自lxml网站:

如果失败,请尝试自己构建http://lxml.de/build.html#building-lxml-on-macos-x

这可能不起作用,所以不要依赖它

否则,还有其他解析器,如lxml.html(应该与lxml一起使用)和其他一些我不确定的解析器。

最新更新