olivia_finder.myrequests.proxy_builders.ssl_proxies
1from typing import List 2from typing_extensions import override 3from bs4 import BeautifulSoup 4import requests 5from .proxy_builder import ProxyBuilder 6 7 8class SSLProxiesBuilder(ProxyBuilder): 9 ''' 10 SSLProxies proxy builder, gets the proxies from https://www.sslproxies.org/ 11 12 Implements the abstract method `ProxyBuilder._parse_request()` to parse the response 13 ''' 14 15 def __init__(self, request_timeout: int = 60): 16 super().__init__( 17 url="https://www.sslproxies.org/", 18 request_timeout=request_timeout 19 ) 20 21 @override 22 def _parse_request(self, response: requests.Response) -> List[str]: 23 ''' 24 Parse the response and return a list of proxies 25 Expected data: 26 27 <tbody> 28 <tr> 29 <td>35.247.248.104</td> 30 <td>3129</td><td>BR</td> 31 <td class="hm">Brazil</td> 32 <td>anonymous</td> 33 <td class="hm"></td> 34 <td class="hx">yes</td> 35 <td class="hm">22 secs ago</td> 36 </tr> 37 ... 38 </tbody> 39 40 Parameters 41 ---------- 42 response : requests.Response 43 The response of the request 44 45 Returns 46 ------- 47 List[str] 48 A list of proxies 49 ''' 50 51 proxies = [] 52 53 # Get the table using beautiful soup 54 soup = BeautifulSoup(response.text, 'html.parser') 55 tbody = soup.find('tbody') 56 57 # iterate over the rows getting the data 58 rows = tbody.find_all('tr') 59 for row in rows: 60 cols = row.find_all('td') 61 62 # add the proxy to the list 63 ip = cols[0].text 64 port = cols[1].text 65 proxies.append(f"{ip}:{port}") 66 67 return proxies
9class SSLProxiesBuilder(ProxyBuilder): 10 ''' 11 SSLProxies proxy builder, gets the proxies from https://www.sslproxies.org/ 12 13 Implements the abstract method `ProxyBuilder._parse_request()` to parse the response 14 ''' 15 16 def __init__(self, request_timeout: int = 60): 17 super().__init__( 18 url="https://www.sslproxies.org/", 19 request_timeout=request_timeout 20 ) 21 22 @override 23 def _parse_request(self, response: requests.Response) -> List[str]: 24 ''' 25 Parse the response and return a list of proxies 26 Expected data: 27 28 <tbody> 29 <tr> 30 <td>35.247.248.104</td> 31 <td>3129</td><td>BR</td> 32 <td class="hm">Brazil</td> 33 <td>anonymous</td> 34 <td class="hm"></td> 35 <td class="hx">yes</td> 36 <td class="hm">22 secs ago</td> 37 </tr> 38 ... 39 </tbody> 40 41 Parameters 42 ---------- 43 response : requests.Response 44 The response of the request 45 46 Returns 47 ------- 48 List[str] 49 A list of proxies 50 ''' 51 52 proxies = [] 53 54 # Get the table using beautiful soup 55 soup = BeautifulSoup(response.text, 'html.parser') 56 tbody = soup.find('tbody') 57 58 # iterate over the rows getting the data 59 rows = tbody.find_all('tr') 60 for row in rows: 61 cols = row.find_all('td') 62 63 # add the proxy to the list 64 ip = cols[0].text 65 port = cols[1].text 66 proxies.append(f"{ip}:{port}") 67 68 return proxies
SSLProxies proxy builder, gets the proxies from https://www.sslproxies.org/
Implements the abstract method ProxyBuilder._parse_request() to parse the response
SSLProxiesBuilder(request_timeout: int = 60)
16 def __init__(self, request_timeout: int = 60): 17 super().__init__( 18 url="https://www.sslproxies.org/", 19 request_timeout=request_timeout 20 )
Constructor
Parameters
- url (str): URL of the proxy list website to get the proxies
- request_timeout (int): Timeout for the proxy list requests