-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* po * checkpoint * checkpoint * checkpoint * checkpoint * checkpoint * checkpoint * checkpoint * checkpoint * checkpoint
- Loading branch information
1 parent
2b06762
commit 68289e1
Showing
16 changed files
with
378 additions
and
361 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Any | ||
from toolz.functoolz import curry | ||
|
||
from scrapy.selector.unified import Selector, SelectorList | ||
from scrapy.http.response.xml import XmlResponse | ||
|
||
from .exceptions import ParseException | ||
|
||
|
||
def node_name(node: Selector) -> str | None: | ||
return node.xpath("name()").get() | ||
|
||
def just_text(node: Selector | SelectorList | Any) -> str | None: | ||
return node.xpath("text()").get() | ||
|
||
def xpath(selector: str, dom: XmlResponse) -> str: | ||
""" | ||
Extracts the text content from the XML response using the given XPath selector. | ||
It does this by appending "/text()" to the selector and returning the first | ||
match. If no match is found, it raises a ParseException. | ||
Args: | ||
selector (str): The XPath selector to match the desired elements. | ||
dom (XmlResponse): The XML response object. | ||
Returns: | ||
str: The extracted text content. | ||
Raises: | ||
ParseException: If the specified XPath selector cannot be found in the XML response. | ||
""" | ||
match dom.xpath(selector + "/text()").get(): | ||
case str(value): | ||
return value | ||
case None: | ||
raise ParseException(f"Could not find {xpath} in {dom.url}") | ||
|
||
xpath = curry(xpath) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Sequence (Iterables, Lists, etc.) functions.""" | ||
|
||
|
||
from typing import Any | ||
|
||
from toolz.functoolz import curry | ||
|
||
|
||
def get(index: int, x: list[Any]) -> Any: | ||
return x[index] | ||
|
||
get = curry(get) |
Oops, something went wrong.