Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes:
A new module,
parsel.parser
, hosts two new classes:HTMLParser
andXMLParser
. These classes have a single, common method,parse
. They are wrappers for the correspondinglxml
parsers.Two new constants have been created:
parsel.parser.html.HTML_PARSER
andparsel.parser.xml.XML_PARSER
, which are instances of those classes. They exist in separate modules so that they are only loaded on demand, lazily, and only instantiated once._ctgroup[*]['_parser']
is now a string with the import path of one of those constants, which theSelector
constructor loads. As a result, when you create multipleSelector
objects from text, a new parser is no longer created each time; the same parser is reused instead.parsel.selector.create_root_node
andparsel.selector.SafeXMLParser
are now deprecated.Now that parser constructor parameters are defined on the new wrapping classes (
parsel.parser.HTMLParser
andparsel.parser.XMLParser
), it’s easier to implement new wrappers for parsers that do not support the same constructor parameters (recover
,encoding
), such as an HTML5 parser.