views:

53

answers:

1

I've got the following BeautifulSoup code, a bit simplified.

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:
    ...

I profiled it, and it's quite slow. I want to try lxml instead but it seems to be a bit unintuitive, compared to BeautifulSoup at least, and I'm not sure it can handle more complex cases.

Can the above code be converted to libxml? I don't want code, just confirmation will do. Thanks.

+1  A: 

Since lxml supports XPath, I would argue: yes, this is definitely possible.

stefanw