lxml: cssselect(): AttributeError: 'lxml.etree._Element' object has no attribute 'cssselect'

旧时模样 提交于 2019-12-06 13:41:44

The difference is in the type of element. Example -

In [12]: root = etree.HTML(html)

In [13]: root = fromstring(html)

In [14]: root2 = etree.HTML(html)

In [15]: type(root)
Out[15]: lxml.html.HtmlElement

In [16]: type(root2)
Out[16]: lxml.etree._Element

lxml.html.HTMLElement has the method cssselect() . Also, HTMLElement is a subclass of etree._Element .

But the lxml.etree._Element does not have that method.

If you want to parse html, you should use lxml.html.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!