-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathGetProxyFromSocks-proxy.py
50 lines (38 loc) · 1.28 KB
/
GetProxyFromSocks-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
import requests
import re
import os
# You can run python from the website https://repl.it/languages
# requirements:
# requests==2.21.0
url = 'https://www.socks-proxy.net'
# url = 'https://www.sslproxies.org/'
fp_unchecked = '{0}/{1}.txt'.format(os.getcwd(), 'UnchekedProxySocks-proxy')
def get_index(url):
header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15'}
print('Getting the website...')
try:
rsp = requests.get(url=url, headers=header)
if rsp.status_code == 200:
print('Success.')
html = rsp.text
return html
else:
exit('Can not get the website.')
except ConnectionError:
exit('ConnectionError.')
def save_proxy(html):
pattern = re.compile('<tr><td>(\d+\.\d+\.\d+\.\d+)<\/td><td>(\d+)<')
result = re.findall(pattern, html)
print('Get {} proxies.'.format(len(result)))
with open(fp_unchecked, 'w+') as f:
for i in result:
proxy = i[0] + ':' + i[1]
print(proxy)
f.write(proxy + '\n')
d = 'Save to {}.\nDone.'.format(fp_unchecked)
print(d)
def main():
html = get_index(url)
save_proxy(html)
if __name__ == '__main__':
main()