Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified _st function to detect doc type #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions parsel/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<html>" in text and "</html>" in text):
return "html"
else:
return "xml"
elif st in _ctgroup:
return st
else:
Expand Down Expand Up @@ -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"]
Expand Down