-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.py
More file actions
77 lines (61 loc) · 2.2 KB
/
proxy.py
File metadata and controls
77 lines (61 loc) · 2.2 KB
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
76
77
import time
from imports import *
def get_free_proxies():
print("Get proxies...")
proxies = free_proxy_list_net()
proxies += free_proxy_cz()
proxies += advanced_name()
print(f'Detected free proxies - {len(set(proxies))}:')
return list(set(proxies))
def free_proxy_list_net():
url = "https://free-proxy-list.net/"
soup = bs4.BeautifulSoup(requests.get(url).content, "html.parser")
proxies = []
for row in soup.find("table", attrs={"class": "table table-striped table-bordered"}).find_all("tr")[1:]:
tds = row.find_all("td")
try:
ip = tds[0].text.strip()
port = tds[1].text.strip()
host = f"{ip}:{port}"
proxies.append(host)
except IndexError:
continue
return proxies
def advanced_name():
proxies = []
for page in range(1, 3):
url = "https://advanced.name/freeproxy?type=https&page=" + str(page)
soup = bs4.BeautifulSoup(requests.get(url).content, "html.parser")
for row in soup.find("table", attrs={"id": "table_proxies"}).find_all("tr")[1:]:
tds = row.find_all("td")
try:
ip = tds[1].text.strip()
port = tds[2].text.strip()
host = f"{ip}:{port}"
proxies.append(host)
except IndexError:
continue
time.sleep(1)
return proxies
def free_proxy_cz():
proxies = []
for page in range(1, 6):
print(page)
url = "http://free-proxy.cz/ru/proxylist/country/all/https/ping/all/" + str(page)
soup = bs4.BeautifulSoup(requests.get(url).content, "html.parser")
for row in soup.find("table", attrs={"id": "proxy_list"}).find_all("tr")[1:]:
tds = row.find_all("td")
try:
ip = tds[0].text.strip()
port = tds[1].text.strip()
host = f"{ip}:{port}"
proxies.append(host)
except IndexError:
continue
time.sleep(1)
return proxies
class ProxyParser:
def __init__(self):
self.all_available_proxy = []
def __call__(self, *args, **kwargs):
self.all_available_proxy = get_free_proxies()