-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxyProviders.py
75 lines (72 loc) · 3.11 KB
/
ProxyProviders.py
1
2
3
4
5
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
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
from Requests import Requests
from bs4 import BeautifulSoup as BeautifulSoup
class Provider:
def __init__(self, url):
self._url = url
self._proxies = []
def getUrl(self):
return self._url
def getProxies(self):
return self._proxies
def updateProxies(self):
raise NotImplementedError
def showProxies(self):
raise NotImplementedError
class SSLProxies(Provider):
url = "https://www.sslproxies.org"
def __init__(self):
super().__init__(SSLProxies.url)
def updateProxies(self):
updated = False
self._proxies = []
requestText = Requests.getText(self.getUrl())
if requestText != None:
soup = BeautifulSoup(requestText, "html.parser")
table = soup.find("table", {"id": "proxylisttable"})
if table != None:
soup = BeautifulSoup(str(table), "html.parser")
tableBody = soup.find("tbody")
if tableBody != None:
soup = BeautifulSoup(str(tableBody), "html.parser")
tableRows = soup.find_all("tr")
if tableRows != None:
for i in tableRows:
soup = BeautifulSoup(str(i), "html.parser")
rowColumns = soup.find_all("td")
if rowColumns != None and len(rowColumns) >= 5:
self._proxies.append((str(rowColumns[0]) + ":" + str(rowColumns[1]) + "#" + str(rowColumns[2]) + "#" + str(rowColumns[4])).replace("<td>", "").replace("</td>", ""))
updated = True
if not updated:
self._proxies = []
def showProxies(self):
for i in self._proxies:
print(i)
class SocksProxy(Provider):
url = "https://www.socks-proxy.net"
def __init__(self):
super().__init__(SSLProxies.url)
def updateProxies(self):
updated = False
self._proxies = []
requestText = Requests.getText(self.getUrl())
if requestText != None:
soup = BeautifulSoup(requestText, "html.parser")
table = soup.find("table", {"id": "proxylisttable"})
if table != None:
soup = BeautifulSoup(str(table), "html.parser")
tableBody = soup.find("tbody")
if tableBody != None:
soup = BeautifulSoup(str(tableBody), "html.parser")
tableRows = soup.find_all("tr")
if tableRows != None:
for i in tableRows:
soup = BeautifulSoup(str(i), "html.parser")
rowColumns = soup.find_all("td")
if rowColumns != None and len(rowColumns) >= 5:
self._proxies.append((str(rowColumns[0]) + ":" + str(rowColumns[1]) + "#" + str(rowColumns[2]) + "#" + str(rowColumns[4])).replace("<td>", "").replace("</td>", ""))
updated = True
if not updated:
self._proxies = []
def showProxies(self):
for i in self._proxies:
print(i)