-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.py
38 lines (30 loc) · 1.17 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
import os
import random
import time
import requests
def get_all_proxies():
with open(os.path.join("proxies.txt"), "r") as file:
proxies = []
for line in file.readlines():
proxies.append(line.replace("\n", "").replace("\r", "").replace("\r\n", "").replace("\n\r", "").replace(" ", ""))
return proxies
def get_random_proxy():
proxies = get_all_proxies()
if len(proxies) > 0:
proxy = random.choice(proxies)
task_proxy = ""
if proxy != "":
temp_proxy = proxy.split(":")
if len(temp_proxy) == 4:
task_proxy = {
"http": "http://" + temp_proxy[2] + ":" + temp_proxy[3] + "@" + temp_proxy[0] + ":" + temp_proxy[1],
"https": "https://" + temp_proxy[2] + ":" + temp_proxy[3] + "@" + temp_proxy[0] + ":" + temp_proxy[1],
}
else:
task_proxy = {
"http": "http://" + temp_proxy[0] + ":" + temp_proxy[1],
"https": "https://" + temp_proxy[0] + ":" + temp_proxy[1],
}
return task_proxy
else:
return ""