-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathproxy.py
64 lines (46 loc) · 1.76 KB
/
proxy.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
# proxy scraping for/from https://free-proxy.cz/
import concurrent.futures
from os import system
from platform import system as current_os
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.webdriver import WebDriver as Chrome
from selenium.webdriver.common.by import By
def clear():
if current_os() == 'Windows': system('cls')
else: system('clear')
# www.free-proxy.cz proxy list URLs
urls = [
'http://free-proxy.cz/en/proxylist/country/all/https/ping/all',
'http://free-proxy.cz/en/proxylist/country/all/https/uptime/all',
'http://free-proxy.cz/en/proxylist/country/all/https/speed/all'
]
# setting webdriver options
options = ChromeOptions()
options.add_argument('-headless')
# getting all proxies
proxies = []
def getProxy(url):
service = ChromeService(executable_path='./chromedriver.exe')
driver = Chrome(options=options, service=service)
driver.get(url)
driver.find_element(By.XPATH, '//*[@id="clickexport"]').click()
proxylist = driver.find_element(By.XPATH, '//*[@id="zkzk"]')
global proxies
proxies.extend(proxylist.text.splitlines())
driver.quit()
clear()
print('[...]\tGetting Proxies from www.free-proxy.cz')
# executing getProxy() parallelly
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(getProxy, urls)
clear()
print('[DONE]\tGetting Proxies from www.free-proxy.cz')
# removing duplicate proxies
proxies = list(set(proxies))
print('[***]\tTotal Proxies Found :', len(proxies))
# writing proxies to file
with open('proxy-list.txt', 'w+') as f:
for i in range(len(proxies)):
f.write(proxies[i]+'\n')
print('[DONE]\tGenerated "proxy-list.txt"')