search for proxy servers that match the specified broker criteria Args: anonymous: whether proxy servers should have minimum level-1 anonymity. countryset: admissible proxy servers locations. secure: whether proxy servers should support HTTP or HTTPS; defaults to HTTP;
(
anonymous: bool = True,
countryset: Optional[Set[str]] = None,
secure: bool = False,
timeout: float = 5.0,
max_shape: int = 5,
search_outside_if_empty: bool = True,
)
| 45 | |
| 46 | |
| 47 | def search_proxy_servers( |
| 48 | anonymous: bool = True, |
| 49 | countryset: Optional[Set[str]] = None, |
| 50 | secure: bool = False, |
| 51 | timeout: float = 5.0, |
| 52 | max_shape: int = 5, |
| 53 | search_outside_if_empty: bool = True, |
| 54 | ) -> List[str]: |
| 55 | """search for proxy servers that match the specified broker criteria |
| 56 | |
| 57 | Args: |
| 58 | anonymous: whether proxy servers should have minimum level-1 anonymity. |
| 59 | countryset: admissible proxy servers locations. |
| 60 | secure: whether proxy servers should support HTTP or HTTPS; defaults to HTTP; |
| 61 | timeout: The maximum timeout for proxy responses; defaults to 5.0 seconds. |
| 62 | max_shape: The maximum number of proxy servers to return; defaults to 5. |
| 63 | search_outside_if_empty: whether countryset should be extended if empty. |
| 64 | |
| 65 | Returns: |
| 66 | A list of proxy server URLs matching the criteria. |
| 67 | |
| 68 | Example: |
| 69 | >>> search_proxy_servers( |
| 70 | ... anonymous=True, |
| 71 | ... countryset={"GB", "US"}, |
| 72 | ... secure=True, |
| 73 | ... timeout=1.0 |
| 74 | ... max_shape=2 |
| 75 | ... ) |
| 76 | [ |
| 77 | "http://103.10.63.135:8080", |
| 78 | "http://113.20.31.250:8080", |
| 79 | ] |
| 80 | """ |
| 81 | proxybroker = FreeProxy( |
| 82 | anonym=anonymous, |
| 83 | country_id=countryset, |
| 84 | elite=True, |
| 85 | https=secure, |
| 86 | timeout=timeout, |
| 87 | ) |
| 88 | |
| 89 | def search_all(proxybroker: FreeProxy, k: int, search_outside: bool) -> List[str]: |
| 90 | candidateset = proxybroker.get_proxy_list(search_outside) |
| 91 | random.shuffle(candidateset) |
| 92 | |
| 93 | positive = set() |
| 94 | |
| 95 | for address in candidateset: |
| 96 | setting = {proxybroker.schema: f"http://{address}"} |
| 97 | |
| 98 | try: |
| 99 | server = proxybroker._FreeProxy__check_if_proxy_is_working(setting) |
| 100 | |
| 101 | if not server: |
| 102 | continue |
| 103 | |
| 104 | positive.add(server) |