mirror of
https://github.com/kennethreitz/requests-html.git
synced 2026-06-05 23:00:20 +00:00
+7
-6
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user