Selector.root is not an instance of lxml.html.HtmlElement even if parser is html
See original GitHub issueI’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:
- Created 7 years ago
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is fixed since #63:
Thanks @kmike !
@kmike what do you think? https://github.com/scrapy/parsel/pull/54