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:
parent
b079953916
commit
92fc86a033
1 changed files with 19 additions and 17 deletions
|
|
@ -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')
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue