Add support for xpath in LxmlHtmlParser.select

The returned results are similar to those of the cssselect method
so there wasn't much to do except calling it.
This commit is contained in:
Laurent Bachelier 2011-04-12 01:00:28 +02:00
commit 92fc86a033

View file

@ -60,6 +60,10 @@ class LxmlHtmlParser(IParser):
""" """
if method == 'cssselect': if method == 'cssselect':
results = element.cssselect(selector) results = element.cssselect(selector)
elif method == 'xpath':
results = element.xpath(selector)
else:
raise NotImplementedError('Only the cssselect and xpath methods are supported')
if nb is None: if nb is None:
return results return results
elif isinstance(nb, basestring) and nb == 'many': elif isinstance(nb, basestring) and nb == 'many':
@ -78,5 +82,3 @@ class LxmlHtmlParser(IParser):
return results[0] if nb == 1 else results return results[0] if nb == 1 else results
else: else:
raise Exception('Unhandled value for kwarg "nb": %s' % nb) raise Exception('Unhandled value for kwarg "nb": %s' % nb)
else:
raise NotImplementedError('Only cssselect method is implemented for the moment')