-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxyFetcher.ts
57 lines (48 loc) · 1.51 KB
/
proxyFetcher.ts
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
import axios from 'axios';
import fs from 'fs-extra';
import { proxyGrabber } from 'proxies-grabber';
import path from 'upath';
const grabber = new proxyGrabber();
grabber.get().then(function (proxies) {
const result = JSON.stringify(proxies, null, 2);
// Custom cookies
const cookies = {
__ga: 'value_of__ga_cookie',
_ga: 'value_of__ga_cookie'
};
// Convert cookies object to string
const cookieString = Object.entries(cookies)
.map(([key, value]) => `${key}=${value}`)
.join('; ');
const lines = splitStringByLines(result);
lines.forEach((line) => {
axios
.post('http://sh.webmanajemen.com/proxyAdd.php', new URLSearchParams({ proxies: line }), {
withCredentials: true,
headers: {
Cookie: cookieString
}
})
.then((res) => {
console.log(res.data);
})
.catch(() => {
//
});
});
fs.appendFileSync(path.join(__dirname, 'proxies.txt'), '\n' + result);
});
function splitStringByLines(inputString: string, linesPerChunk = 500) {
// Split the input string into an array of lines
const lines = inputString.split('\n');
// Initialize the result array
const chunks = [];
// Loop through the lines and create chunks
for (let i = 0; i < lines.length; i += linesPerChunk) {
// Get a chunk of the specified number of lines
const chunk = lines.slice(i, i + linesPerChunk);
// Join the chunk back into a string and push it to the chunks array
chunks.push(chunk.join('\n'));
}
return chunks;
}