Can someone explain why the first call works root.cssselect()and the second one fails?
from lxml.html import fromstring
from lxml import etree
html='<html><a href="http://example.com">example</a></html'
root = fromstring(html)
print 'via fromstring', repr(root)
print root.cssselect("a")
root2 = etree.HTML(html)
print 'via etree.HTML()', repr(root2)
root2.cssselect("a")
I get:
Traceback (most recent call last):
File "/home/foo_eins_d/src/foo.py", line 11, in <module>
root2.cssselect("a")
AttributeError: 'lxml.etree._Element' object has no attribute 'cssselect'
Version: lxml==3.4.4
source
share