Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
撤回更改
Browse files Browse the repository at this point in the history
dream2333 committed Jun 13, 2024
1 parent 7407342 commit 8678830
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions parsel/selector.py
Original file line number Diff line number Diff line change
@@ -423,6 +423,7 @@ class Selector:
"_huge_tree",
"root",
"_text",
"_text_lazy_html_root",
"body",
"__weakref__",
]
@@ -507,6 +508,10 @@ def __init__(
self._expr = _expr
self._huge_tree = huge_tree
self._text = text
# self._text_to_html_root is used to store a temporary root node when
# converting text to html for xpath queries. This is needed because
# the text may not be valid html and we need to convert it to html
self._text_lazy_html_root =None

def __getstate__(self) -> Any:
raise TypeError("can't pickle Selector objects")
@@ -606,7 +611,9 @@ def xpath(
)
else:
try:
xpathev = self._get_root(self._text or "", type="html").xpath
if self._text_lazy_html_root is None:
self._text_lazy_html_root = self._get_root(self._text or "", type="html")
xpathev = self._text_lazy_html_root.xpath
except AttributeError:
return typing.cast(
SelectorList[_SelectorType], self.selectorlist_cls([])
@@ -625,7 +632,7 @@ def xpath(
except etree.XPathError as exc:
raise ValueError(f"XPath error: {exc} in {query}")

if type(result) is not list:
if not isinstance(result, list):
result = [result]

result = [

0 comments on commit 8678830

Please sign in to comment.