跳转至

Baidu

Classes

BaiDuItem

Bases: BaseSearchItem

Represents a single BaiDu search result item.

A class that processes and stores individual search result data from BaiDu image search.

Attributes:

Name Type Description
origin dict

The raw, unprocessed data of the search result item.

thumbnail str

URL of the thumbnail image.

url str

URL of the webpage containing the original image.

Source code in PicImageSearch/model/baidu.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class BaiDuItem(BaseSearchItem):
    """Represents a single BaiDu search result item.

    A class that processes and stores individual search result data from BaiDu image search.

    Attributes:
        origin (dict): The raw, unprocessed data of the search result item.
        thumbnail (str): URL of the thumbnail image.
        url (str): URL of the webpage containing the original image.
    """

    def __init__(self, data: dict[str, Any], **kwargs: Any) -> None:
        """Initialize a BaiDu search result item.

        Args:
            data (dict[str, Any]): A dictionary containing the raw search result data from BaiDu.
            **kwargs (Any): Additional keyword arguments passed to the parent class.
        """
        super().__init__(data, **kwargs)

    def _parse_data(self, data: dict[str, Any], **kwargs: Any) -> None:
        """Parse the raw search result data into structured attributes.

        Args:
            data (dict[str, Any]): Raw dictionary data from BaiDu search result.
            **kwargs (Any): Additional keyword arguments (unused).

        Note:
            Some previously supported attributes have been deprecated:
            - similarity: Percentage of image similarity
            - title: Title of the source webpage
        """
        # deprecated attributes
        # self.similarity: float = round(float(data["simi"]) * 100, 2)
        # self.title: str = data["fromPageTitle"]
        self.thumbnail: str = data["thumbUrl"]
        self.url: str = data["fromUrl"]

Functions

__init__(data, **kwargs)

Initialize a BaiDu search result item.

Parameters:

Name Type Description Default
data dict[str, Any]

A dictionary containing the raw search result data from BaiDu.

required
**kwargs Any

Additional keyword arguments passed to the parent class.

{}
Source code in PicImageSearch/model/baidu.py
17
18
19
20
21
22
23
24
def __init__(self, data: dict[str, Any], **kwargs: Any) -> None:
    """Initialize a BaiDu search result item.

    Args:
        data (dict[str, Any]): A dictionary containing the raw search result data from BaiDu.
        **kwargs (Any): Additional keyword arguments passed to the parent class.
    """
    super().__init__(data, **kwargs)

BaiDuResponse

Bases: BaseSearchResponse[BaiDuItem]

Encapsulates a complete BaiDu reverse image search response.

A class that handles and stores the full response from a BaiDu reverse image search, including multiple search results.

Attributes:

Name Type Description
origin dict

The complete raw response data from BaiDu.

raw list[BaiDuItem]

List of processed search results as BaiDuItem instances.

url str

URL of the search results page on BaiDu.

Source code in PicImageSearch/model/baidu.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class BaiDuResponse(BaseSearchResponse[BaiDuItem]):
    """Encapsulates a complete BaiDu reverse image search response.

    A class that handles and stores the full response from a BaiDu reverse image search,
    including multiple search results.

    Attributes:
        origin (dict): The complete raw response data from BaiDu.
        raw (list[BaiDuItem]): List of processed search results as BaiDuItem instances.
        url (str): URL of the search results page on BaiDu.
    """

    def __init__(self, resp_data: dict[str, Any], resp_url: str, **kwargs: Any):
        """Initialize a BaiDu search response.

        Args:
            resp_data (dict[str, Any]): The raw JSON response from BaiDu's API.
            resp_url (str): The URL of the search results page.
            **kwargs (Any): Additional keyword arguments passed to the parent class.
        """
        super().__init__(resp_data, resp_url, **kwargs)

    def _parse_response(self, resp_data: dict[str, Any], **kwargs: Any) -> None:
        """Parse the raw response data into a list of search result items.

        Args:
            resp_data (dict[str, Any]): Raw response dictionary from BaiDu's API.
            **kwargs (Any): Additional keyword arguments (unused).

        Note:
            If resp_data is empty or invalid, an empty list will be returned.
        """
        self.raw: list[BaiDuItem] = (
            [BaiDuItem(i) for i in resp_data["data"]["list"]] if resp_data else []
        )

Functions

__init__(resp_data, resp_url, **kwargs)

Initialize a BaiDu search response.

Parameters:

Name Type Description Default
resp_data dict[str, Any]

The raw JSON response from BaiDu's API.

required
resp_url str

The URL of the search results page.

required
**kwargs Any

Additional keyword arguments passed to the parent class.

{}
Source code in PicImageSearch/model/baidu.py
57
58
59
60
61
62
63
64
65
def __init__(self, resp_data: dict[str, Any], resp_url: str, **kwargs: Any):
    """Initialize a BaiDu search response.

    Args:
        resp_data (dict[str, Any]): The raw JSON response from BaiDu's API.
        resp_url (str): The URL of the search results page.
        **kwargs (Any): Additional keyword arguments passed to the parent class.
    """
    super().__init__(resp_data, resp_url, **kwargs)