Skip to content

Address

Developer docs

A class to represent an address

Source code in src/whitepyges/address.py
  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
 43
 44
 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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class Address:
    """
    A class to represent an address
    """

    def __init__(
        self,
        street: str = None,
        city: str = None,
        state: str = None,
        zip_code: str = None,
    ) -> None:
        """
        Initialize a new Address object

        Args:
            street (str): The street of the address
            city (str): The city of the address
            state (str): The state of the address
            zip_code (str): The zip code of the address

        Returns:
            None
        """

        if not street:
            raise ValueError("Street is required")

        if not city:
            raise ValueError("City is required")

        if not state and not zip_code:
            raise ValueError("State or zip code is required")

        self.street = helper.format_street(street)
        self.location = helper.format_location(city, state, zip_code)

        self.headers = config.HEADERS

    def search(
        self,
        timeout: int = 10,
        max_retries: int = 3,
        randomize_headers: bool = False,
        ignore_robots: bool = False,
    ) -> list[dict] | None:
        """
        Perform a search for the address

        Args:
            timeout (int, optional): The timeout for the request. Defaults to 10.
            max_retries (int, optional): The maximum number of retries. Defaults to 3.
            randomize_headers (bool, optional): Randomize the headers for the request. Defaults to False.
            ignore_robots (bool, optional): Ignore the robots.txt file. Defaults to False.

        Returns:
            list[dict] | None: Possible data for the address
        """

        endpoint: str = "address"

        url: str = helper.get_endpoint(
            "address", endpoint, address=self.street, location=self.location
        )

        headers: dict = self.headers
        if randomize_headers:
            headers = helper.get_random_headers()

        response: requests.Response = helper.make_request_with_retries(
            url, headers, max_retries, timeout, ignore_robots
        )

        soup: BeautifulSoup = BeautifulSoup(response.text, "html.parser")

        residents: list[dict] = []

        for div in soup.find_all("div", {"data-qa-selector": "resident"}):
            person_name: str = div.find(
                "a", class_="tw-text-link tw-font-bold"
            ).get_text(strip=True)
            person_url: str = div.find("a", class_="tw-text-link tw-font-bold")["href"]
            person_age: str = div.find("span", class_="tw-font-bold").get_text(
                strip=True
            )

            if person_age == "--":
                person_age = None

            person_data: dict = {
                "name": person_name,
                "url": config.BASE_URL + person_url,
                "age": person_age,
            }

            residents.append(person_data)

        return residents

    def __repr__(self) -> str:
        """
        Return the string representation of the object

        Returns:
            str: The string representation of the object
        """

        return helper.format_repr(self)

    def __str__(self) -> str:
        """
        Return the string representation of the object

        Returns:
            str: The string representation of the object
        """

        return helper.format_str(self)

__init__

Initialize a new Address object

Parameters:

Name Type Description Default
street str

The street of the address

None
city str

The city of the address

None
state str

The state of the address

None
zip_code str

The zip code of the address

None

Returns:

Type Description
None

None

Source code in src/whitepyges/address.py
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
43
44
45
def __init__(
    self,
    street: str = None,
    city: str = None,
    state: str = None,
    zip_code: str = None,
) -> None:
    """
    Initialize a new Address object

    Args:
        street (str): The street of the address
        city (str): The city of the address
        state (str): The state of the address
        zip_code (str): The zip code of the address

    Returns:
        None
    """

    if not street:
        raise ValueError("Street is required")

    if not city:
        raise ValueError("City is required")

    if not state and not zip_code:
        raise ValueError("State or zip code is required")

    self.street = helper.format_street(street)
    self.location = helper.format_location(city, state, zip_code)

    self.headers = config.HEADERS

__repr__

Return the string representation of the object

Returns:

Name Type Description
str str

The string representation of the object

Source code in src/whitepyges/address.py
107
108
109
110
111
112
113
114
115
def __repr__(self) -> str:
    """
    Return the string representation of the object

    Returns:
        str: The string representation of the object
    """

    return helper.format_repr(self)

__str__

Return the string representation of the object

Returns:

Name Type Description
str str

The string representation of the object

Source code in src/whitepyges/address.py
117
118
119
120
121
122
123
124
125
def __str__(self) -> str:
    """
    Return the string representation of the object

    Returns:
        str: The string representation of the object
    """

    return helper.format_str(self)

search

Perform a search for the address

Parameters:

Name Type Description Default
timeout int

The timeout for the request. Defaults to 10.

10
max_retries int

The maximum number of retries. Defaults to 3.

3
randomize_headers bool

Randomize the headers for the request. Defaults to False.

False
ignore_robots bool

Ignore the robots.txt file. Defaults to False.

False

Returns:

Type Description
list[dict] | None

list[dict] | None: Possible data for the address

Source code in src/whitepyges/address.py
 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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def search(
    self,
    timeout: int = 10,
    max_retries: int = 3,
    randomize_headers: bool = False,
    ignore_robots: bool = False,
) -> list[dict] | None:
    """
    Perform a search for the address

    Args:
        timeout (int, optional): The timeout for the request. Defaults to 10.
        max_retries (int, optional): The maximum number of retries. Defaults to 3.
        randomize_headers (bool, optional): Randomize the headers for the request. Defaults to False.
        ignore_robots (bool, optional): Ignore the robots.txt file. Defaults to False.

    Returns:
        list[dict] | None: Possible data for the address
    """

    endpoint: str = "address"

    url: str = helper.get_endpoint(
        "address", endpoint, address=self.street, location=self.location
    )

    headers: dict = self.headers
    if randomize_headers:
        headers = helper.get_random_headers()

    response: requests.Response = helper.make_request_with_retries(
        url, headers, max_retries, timeout, ignore_robots
    )

    soup: BeautifulSoup = BeautifulSoup(response.text, "html.parser")

    residents: list[dict] = []

    for div in soup.find_all("div", {"data-qa-selector": "resident"}):
        person_name: str = div.find(
            "a", class_="tw-text-link tw-font-bold"
        ).get_text(strip=True)
        person_url: str = div.find("a", class_="tw-text-link tw-font-bold")["href"]
        person_age: str = div.find("span", class_="tw-font-bold").get_text(
            strip=True
        )

        if person_age == "--":
            person_age = None

        person_data: dict = {
            "name": person_name,
            "url": config.BASE_URL + person_url,
            "age": person_age,
        }

        residents.append(person_data)

    return residents

Features

  • Search for residents at a specific address
  • Returns names, profile URLs, and ages (if available)
  • Handles request retries and optional header randomization

Example Usage

from whitepyges import Address

address: Address = Address(street='123 Test Street', city='New York', state='NY')
info: dict = address.search()

print(info)

Example Response

[
    {
        "name": "Jon Doe",
        "url": "https://www.whitepages.com/name/Jon-Doe/Example-WA/random_numbers",
        "age": "22"
    },
    {
        "name": "Jon Doe-2",
        "url": "https://www.whitepages.com/name/Jon-Doe-2/Example-WA/random_numbers-2",
        "age": null
    }
]