BeautifulSoup太慢了。 lxml可以这样做吗?

时间:2010-10-28 09:19:28

标签: python beautifulsoup lxml

我有以下BeautifulSoup代码,有点简化。

soup = BeautifulSoup(html)
for item in soup.findAll('div',id=compile('^result_')):
  q = item.find('a',{'class':'title'})
  if q:
    ...
  q = item.find('div',{'class':['one','two']})
  if q:
    ...

我描述了它,而且速度很慢。我想尝试lxml,但它似乎有点不直观,至少与BeautifulSoup相比,我不确定它能处理更复杂的情况。

上面的代码可以转换为libxml吗?我不想要代码,只需确认即可。感谢。

1 个答案:

答案 0 :(得分:1)

lxml supports XPath以来,我认为:是的,这绝对是可能的。