Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
This commit is contained in:
2018-02-28 06:59:14 -05:00
parent 26c9f08960
commit 95886bdd25
2 changed files with 11 additions and 7 deletions
+7 -6
View File
@@ -136,12 +136,13 @@ class BaseParser:
:class:`Element <Element>` found.
"""
selected = self.lxml.xpath(selector)
try:
c = [Element(element=e, url=self.url, default_encoding=_encoding or self.encoding) for e in selected]
# Sanity check.
[e.keys for e in c]
except AttributeError:
c = selected
c = []
for selection in selected:
if not isinstance(selection, etree._ElementUnicodeResult):
element = Element(element=selection, url=self.url, default_encoding=_encoding or self.encoding)
else:
element = selection
c.append(element)
if first:
try:
+4 -1
View File
@@ -59,6 +59,9 @@ def test_xpath():
html = r.html.xpath('/html', first=True)
assert 'no-js' in html.attrs['class']
a_hrefs = r.html.xpath('//a/@href')
print(a_hrefs)
def test_html_loading():
doc = """<a href='https://httpbin.org'>"""
@@ -77,4 +80,4 @@ def test_anchor_links():
if __name__ == '__main__':
test_anchor_links()
test_xpath()