question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selector.root is not an instance of lxml.html.HtmlElement even if parser is html

See original GitHub issue

I’m trying to use lxml.Cleaner without parsing response multiple times:

from lxml.html.clean import Cleaner
cleaner = Cleaner()
sel = parsel.Selector("<html><body><style>.p {width:10px}</style>hello</body></html>"
cleaner.clean_html(sel.root)

This doesn’t work because Cleaner needs a lxml.html.HtmlElement instance, while Selector.root is always lxml.etree._Element, so it doesn’t have a required .rewrite_links method.

Why is lxml.etree.HtmlParser used for html and not lxml.html.HtmlParser?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eliasdornelescommented, Nov 21, 2016

This is fixed since #63:

>>> import parsel
>>> sel = parsel.Selector(u'<html><body><h1>oi</h1></body></html>')
>>> type(sel.root)
lxml.html.HtmlElement

Thanks @kmike !

0reactions
eliasdornelescommented, Aug 10, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing HTML - LXML
It is based on lxml's HTML parser, but provides a special Element API for HTML ... If no value is given, or if...
Read more >
Equivalent to InnerHTML when using lxml.html to parse HTML
I find none of the answers satisfying, some are even in Python 2. ... from lxml import etree, html # generate some HTML...
Read more >
Web scraping using Python: requests and lxml - GitHub Pages
lxml is a tool for working with HTML and XML documents, represented as an element tree. It evaluates XPath and CSS selectors to...
Read more >
Parsing HTML: a guide to select the right library
Actually, you may not need even to do that, if you choose a popular parser ... For instance, CSSelly, which is a parser...
Read more >
Source Code for Package lxml.html
IN NO EVENT SHALL IAN BICKING OR 23 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 # EXEMPLARY, OR CONSEQUENTIAL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found