-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
26 lines (23 loc) · 943 Bytes
/
main.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
const axios = require('axios');
const cheerio = require('cheerio');
const getRandomProxy = async () => {
const url = 'https://free-proxy-list.net/';
const headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
};
try {
const { data } = await axios.get(url, { headers });
const $ = cheerio.load(data);
const proxies = [];
$('tbody tr').each((i, element) => {
const ip = $(element).children().first().text();
const port = $(element).children().first().next().text();
proxies.push({ ip, port });
});
const randomProxy = proxies[Math.floor(Math.random() * proxies.length)];
console.log(`Random proxy: ${randomProxy.ip}:${randomProxy.port}`);
} catch (error) {
console.log(`Error: ${error.message}`);
}
};
getRandomProxy();