From de33d3f550a8efeedc05ab19609120f807d1e5ee Mon Sep 17 00:00:00 2001 From: Shivam Shandilya Date: Wed, 2 Mar 2022 23:48:24 +0530 Subject: [PATCH] modified _st function to detect doc type Signed-off-by: Shivam Shandilya --- parsel/selector.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/parsel/selector.py b/parsel/selector.py index 45c88d09..5cd491b7 100644 --- a/parsel/selector.py +++ b/parsel/selector.py @@ -41,9 +41,12 @@ def __init__(self, *args, **kwargs) -> None: } -def _st(st: Optional[str]) -> str: +def _st(st: Optional[str], text) -> str: if st is None: - return "html" + if("" in text and "" in text): + return "html" + else: + return "xml" elif st in _ctgroup: return st else: @@ -267,7 +270,7 @@ def __init__( base_url: Optional[str] = None, _expr: Optional[str] = None, ) -> None: - self.type = st = _st(type or self._default_type) + self.type = st = _st(type or self._default_type, text) self._parser = _ctgroup[st]["_parser"] self._csstranslator = _ctgroup[st]["_csstranslator"] self._tostring_method = _ctgroup[st]["_tostring_method"]