forked from sunny9577/proxy-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.js
305 lines (268 loc) · 13.6 KB
/
spec.js
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
var fs = require('fs');
var db = require('./db');
var https = require("https");
var config = require('./config');
var { getName } = require('country-list');
describe('Scrapers', function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000; //10 min timeout
var saveToDb = config.SAVE_TO_DB;
var proxyCount = 0;
var proxies = new Object();
var proxiesCsv = '';
var proxiesTxt = '';
proxies.lastUpdated = new Date();
it('Proxynova Scraper', function() {
console.log('Running... Proxynova');
var pages = ['https://www.proxynova.com/proxy-server-list/country-bd/ ', 'https://www.proxynova.com/proxy-server-list/country-br/ ', 'https://www.proxynova.com/proxy-server-list/country-cl/ ', 'https://www.proxynova.com/proxy-server-list/country-cn/ ', 'https://www.proxynova.com/proxy-server-list/country-co/ ', 'https://www.proxynova.com/proxy-server-list/country-fr/ ', 'https://www.proxynova.com/proxy-server-list/country-de/ ', 'https://www.proxynova.com/proxy-server-list/country-hk/ ', 'https://www.proxynova.com/proxy-server-list/country-in/ ', 'https://www.proxynova.com/proxy-server-list/country-id/ ', 'https://www.proxynova.com/proxy-server-list/country-jp/ ', 'https://www.proxynova.com/proxy-server-list/country-ke/ ', 'https://www.proxynova.com/proxy-server-list/country-nl/ ', 'https://www.proxynova.com/proxy-server-list/country-pl/ ', 'https://www.proxynova.com/proxy-server-list/country-ru/ ', 'https://www.proxynova.com/proxy-server-list/country-rs/ ', 'https://www.proxynova.com/proxy-server-list/country-kr/ ', 'https://www.proxynova.com/proxy-server-list/country-tw/ ', 'https://www.proxynova.com/proxy-server-list/country-th/ ', 'https://www.proxynova.com/proxy-server-list/country-ua/ ', 'https://www.proxynova.com/proxy-server-list/country-gb/ ', 'https://www.proxynova.com/proxy-server-list/country-us/ ', 'https://www.proxynova.com/proxy-server-list/country-ve/ ', 'https://www.proxynova.com/proxy-server-list/country-ir/ ', 'https://www.proxynova.com/proxy-server-list/country-tr/ ', 'https://www.proxynova.com/proxy-server-list/country-na/ ', 'https://www.proxynova.com/proxy-server-list/country-mz/ ', 'https://www.proxynova.com/proxy-server-list/country-it/ ', 'https://www.proxynova.com/proxy-server-list/country-eg/ ', 'https://www.proxynova.com/proxy-server-list/country-bg/'];
var proxynova = [];
var i = 0;
function loadPage() {
page = pages[i];
console.log("Loading " + page);
browser.driver.get(page);
browser.driver.findElement(by.tagName('tbody')).findElements(by.tagName('tr')).then((data) => {
data.forEach(row => {
row.findElements(by.tagName('td')).then((col) => {
if (col[1] != undefined) {
var proxy = new Object();
col[0].getText().then((text) => {
proxy.ip = text
}).then(() => {
col[1].getText().then((text) => {
proxy.port = text
})
}).then(() => {
col[5].getText().then((text) => {
proxy.country = text
})
}).then(() => {
col[6].getText().then((text) => {
proxy.anonymity = text
})
}).then(() => {
proxy.type = 'HTTP/HTTPS';
}).then(() => {
proxiesCsv += `${proxy.ip},${proxy.port},${proxy.country},${proxy.anonymity},${proxy.type}\n`
proxiesTxt += `${proxy.ip}:${proxy.port}\n`
proxynova.push(proxy);
proxyCount++;
saveIntoDb(proxy);
})
.catch((err) => {
console.log("Exception Occured! in Proxynova" + err.stack);
})
}
});
});
}).then(() => {
i++;
if (i < pages.length)
loadPage();
else
moveToAllProxies('proxynova', proxynova);
console.log(`Got ${proxyCount} proxies from proxynova`);
proxyCount = 0;
}).catch((err) => {
console.log("Exception Occured! in Proxynova" + err.stack);
});
}
loadPage();
});
it('US-proxy.org Scraper', function() {
console.log('Running... US-proxy.org');
browser.driver.get('https://www.us-proxy.org/');
dataidxid = 3;
var usProxy = [];
function nextPage() {
browser.driver.findElement(by.id('proxylisttable')).findElements(by.tagName('tr')).then((rows) => {
rows.forEach(row => {
var proxy = new Object();
row.findElements(by.tagName('td')).then((cols) => {
if (cols.length > 0) {
cols[0].getText().then((text) => {
proxy.ip = text;
}).then(() => {
cols[1].getText().then((text) => {
proxy.port = text;
})
}).then(() => {
proxy.country = 'United States';
}).then(() => {
cols[4].getText().then((text) => {
proxy.type = text;
})
}).then(() => {
cols[4].getText().then((text) => {
proxy.anonymity = 'HTTP/HTTPS';
})
}).then(() => {
proxiesCsv += `${proxy.ip},${proxy.port},${proxy.country},${proxy.anonymity},${proxy.type}\n`
proxiesTxt += `${proxy.ip}:${proxy.port}\n`
usProxy.push(proxy);
proxyCount++;
saveIntoDb(proxy);
}).catch((err) => {
console.log("Exception Occured! in US Proxy" + err);
})
}
})
});
}).then(() => {
if (dataidxid <= 11) {
dataidxid++;
browser.driver.findElement(by.xpath('//*[@id="proxylisttable_next"]/a')).click();
nextPage();
} else {
moveToAllProxies('usproxy', usProxy);
console.log(`Got ${proxyCount} proxies from US proxy`);
proxyCount = 0;
}
}).catch((err) => {
console.log("Exception Occured! in US Proxy" + err);
})
}
nextPage();
})
it('hidemyna.me Scraper', function() {
console.log('Running... hidemyna.me');
var hidemyname = [];
var i = 0;
function loadPage() {
var curPage = i * 64;
browser.driver.get('https://hidemyna.me/en/proxy-list/?maxtime=1000&anon=4&start=' + curPage + '#list');
if (i == 0)
browser.driver.sleep(10000);
browser.driver.findElement(by.tagName('table')).findElement(by.tagName('tbody')).then((body) => {
body.findElements(by.tagName('tr')).then((rows) => {
rows.forEach(row => {
row.findElements(by.tagName('td')).then((cols) => {
var proxy = new Object();
cols[0].getText().then((text) => {
proxy.ip = text;
}).then(() => {
cols[1].getText().then((text) => {
proxy.port = text;
})
}).then(() => {
cols[2].getText().then((text) => {
proxy.country = text;
})
}).then(() => {
cols[4].getText().then((text) => {
proxy.type = text;
})
}).then(() => {
cols[5].getText().then((text) => {
proxy.anonymity = text;
})
}).then(() => {
proxiesCsv += `${proxy.ip},${proxy.port},${proxy.country},${proxy.anonymity},${proxy.type}\n`
proxiesTxt += `${proxy.ip}:${proxy.port}\n`
hidemyname.push(proxy);
proxyCount++;
saveIntoDb(proxy);
}).catch((err) => {
console.log("Exception Occured! in hidemyna.me" + err);
})
})
});
})
}).then(() => {
i++;
if (i <= 10)
loadPage();
else {
moveToAllProxies('hidemyname', hidemyname);
console.log(`Got ${proxyCount} proxies from hidemyname`);
proxyCount = 0;
}
}).catch((err) => {
console.log("Exception Occured! in hidemyname" + err);
});
}
loadPage();
});
it('pzzqz.com API', async function () {
console.log('Running... pzzqz.com API');
var options = {
'method': 'GET',
'hostname': 'api.pzzqz.com',
'path': '/api/v1.0/proxy/list/',
'headers': {
'X-Api-Key': process.env.PZZQZ_KEY,
},
'maxRedirects': 20
};
await new Promise((resolve, reject) => {
var pzzqzProxies = [];
const req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log('pzzqz response: ' + body.toString());
try {
let responseInstance = JSON.parse(body.toString());
for (const pzzqzProxy of responseInstance.data) {
let proxyIp = pzzqzProxy.proxy.split(':')[0];
let proxyPort = pzzqzProxy.proxy.split(':')[1];
var proxy = {
ip: proxyIp,
port: proxyPort,
country: getName(pzzqzProxy.country),
type: pzzqzProxy.protocols,
anonymity: pzzqzProxy.anonymity
}
proxiesCsv += `${proxy.ip},${proxy.port},${proxy.country},${proxy.anonymity},${proxy.type}\n`
proxiesTxt += `${proxy.ip}:${proxy.port}\n`
pzzqzProxies.push(proxy);
proxyCount++;
}
saveIntoDb(proxy);
moveToAllProxies('pzzqz', pzzqzProxies);
console.log(`Got ${responseInstance.data.length} proxies from pzzqz.com`);
resolve(responseInstance);
} catch (error) {
console.error(error);
reject(error);
}
});
res.on("error", function (error) {
console.error(error);
reject(error);
});
setTimeout(function () {
reject('Promise timed out after ' + 10000 + ' ms');
}, 10000);
});
req.end();
}).catch((err) => {
console.log(err);
})
});
function saveIntoDb(proxy) {
if (!saveToDb)
return;
var sql = "INSERT into proxies_tb (`proxy`,`port`,`country`,`type`,`anonymity`) VALUES('" + proxy.ip + "'," + proxy.port + ",'" + proxy.country + "','" + proxy.type + "','" + proxy.anonymity + "')";
db.query(sql, (err, result) => {
if (err)
console.log(err)
})
}
function moveToAllProxies(name, arr) {
proxies[name] = arr;
}
it('Save', function() {
fs.writeFile('proxies.json', JSON.stringify(proxies), function(err, data) {
console.log("Successfully Saved proxies");
});
fs.writeFile('proxies.csv', proxiesCsv, function(err, data) {
console.log("Successfully Saved proxies");
});
fs.writeFile('proxies.txt', proxiesTxt, function(err, data) {
console.log("Successfully Saved proxies");
});
})
});