forked from iw4p/proxy-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxyScraper.py
More file actions
242 lines (203 loc) · 5.63 KB
/
proxyScraper.py
File metadata and controls
242 lines (203 loc) · 5.63 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import argparse
import os
import re
import threading
import requests
from bs4 import BeautifulSoup
pathTextFile = ""
proxyType = ""
# From spys.me
def spys_me_scraper(proxytype):
response = requests.get("https://spys.me/" + proxytype + ".txt")
proxies = response.text
pattern = re.compile("\\d{1,3}(?:\\.\\d{1,3}){3}(?::\\d{1,5})?")
matcher = re.findall(pattern, proxies)
with open(pathTextFile, "a") as txt_file:
for proxy in matcher:
txt_file.write(proxy + "\n")
# From proxyscrape.com
def proxy_scrape_scraper(proxytype, timeout, country):
response = requests.get(
"https://api.proxyscrape.com/?request=getproxies&proxytype="
+ proxytype
+ "&timeout="
+ timeout
+ "&country="
+ country,
)
proxies = response.text
with open(pathTextFile, "a") as txt_file:
txt_file.write(proxies)
# From proxy-list.download
def proxy_list_download_scraper(url, proxy_type, anon):
session = requests.session()
url = url + "?type=" + proxy_type + "&anon=" + anon
html = session.get(url).text
if args.verbose:
print(url)
with open(pathTextFile, "a") as txt_file:
for line in html.split("\n"):
if len(line) > 0:
txt_file.write(line)
def scrape_proxies(url):
page = requests.get(url)
if args.verbose:
print(url + " scraped successfully")
soup = BeautifulSoup(page.text, "html.parser")
proxies = set()
table = soup.find("table", attrs={"class": "table table-striped table-bordered"})
for row in table.findAll("tr"):
count = 0
proxy = ""
for cell in row.findAll("td"):
if count == 1:
proxy += ":" + cell.text.replace(" ", "")
proxies.add(proxy)
break
proxy += cell.text.replace(" ", "")
count += 1
with open(pathTextFile, "a") as txt_file:
for line in proxies:
txt_file.write("".join(line) + "\n")
# output watcher
def output():
if os.path.exists(pathTextFile):
os.remove(pathTextFile)
elif not os.path.exists(pathTextFile):
with open(pathTextFile, "w"):
pass
def start_https():
threading.Thread(target=scrape_proxies, args=("http://sslproxies.org",)).start()
threading.Thread(
target=proxy_list_download_scraper,
args=(
"https://www.proxy-list.download/api/v1/get",
"https",
"elite",
),
).start()
output()
def start_http():
threading.Thread(
target=scrape_proxies,
args=("http://free-proxy-list.net",),
).start()
threading.Thread(target=scrape_proxies, args=("http://us-proxy.org",)).start()
threading.Thread(
target=proxy_scrape_scraper,
args=(
"http",
"1000",
"All",
),
).start()
for status in ["elite", "transparent", "anonymous"]:
threading.Thread(
target=proxy_list_download_scraper,
args=(
"https://www.proxy-list.download/api/v1/get",
"http",
status,
),
).start()
threading.Thread(target=spys_me_scraper, args=("proxy",)).start()
output()
def start_socks():
threading.Thread(target=scrape_proxies, args=("http://socks-proxy.net",)).start()
threading.Thread(
target=proxy_scrape_scraper,
args=(
"socks4",
"1000",
"All",
),
).start()
threading.Thread(
target=proxy_scrape_scraper,
args=(
"socks5",
"1000",
"All",
),
).start()
for socks in ["socks5", "socks4"]:
threading.Thread(
target=proxy_list_download_scraper,
args=(
"https://www.proxy-list.download/api/v1/get",
socks,
"elite",
),
).start()
threading.Thread(target=spys_me_scraper, args=("socks",)).start()
output()
def start_socks4():
threading.Thread(
target=proxy_scrape_scraper,
args=(
"socks4",
"1000",
"All",
),
).start()
threading.Thread(
target=proxy_list_download_scraper,
args=(
"https://www.proxy-list.download/api/v1/get",
"socks4",
"elite",
),
).start()
output()
def start_socks5():
threading.Thread(
target=proxy_scrape_scraper,
args=(
"socks5",
"1000",
"All",
),
).start()
threading.Thread(
target=proxy_list_download_scraper,
args=(
"https://www.proxy-list.download/api/v1/get",
"socks5",
"elite",
),
).start()
output()
if __name__ == "__main__":
global proxy
parser = argparse.ArgumentParser()
parser.add_argument(
"-p",
"--proxy",
help="Supported proxy type: http ,https, socks, socks4, socks5",
required=True,
)
parser.add_argument(
"-o",
"--output",
help="output file name to save .txt file",
default="output.txt",
)
parser.add_argument(
"-v",
"--verbose",
help="increase output verbosity",
action="store_true",
)
args = parser.parse_args()
proxy = args.proxy
pathTextFile = args.output
if proxy == "https":
start_https()
if proxy == "http":
start_http()
if proxy == "socks":
start_socks()
if proxy == "socks4":
start_socks4()
if proxy == "socks5":
start_socks5()