-
Notifications
You must be signed in to change notification settings - Fork 1
/
shuapiao.js
80 lines (70 loc) · 1.91 KB
/
shuapiao.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
const axios = require('axios').default;
const cheerio = require('cheerio');
// nihao
function random() {
return Math.round(Math.random()*(5-1)+1); // 返回一个随机数字
}
let time = null;
async function main(page) {
const proxies = [];
{
//axios.get(`http://www.89ip.cn/index_${2}.html`);
const { data } = await axios("get",{url: `http://www.superfastip.com/welcome/freeip/${page}`});
const $ = cheerio.load(data);
const trs = $("tbody").children();
const result = trs.map(function () {
//const el = this.children[0].firstElementChild.innerHTML
//console.log(el)
const el = $(this).children();
return {
host: el.first().text().trim(),
port: +el.eq(1).text().trim(),
};
});
proxies.push(...result.toArray());
console.log(proxies)
}
// 添加一个东西
let index = 0;
let i = 0;
let errTotal = 0;
function testIPIsNull() { // 检测是否ip使用完毕
if (index > proxies.length) {
clearInterval(time);
main(random())
console.log('结束');
}
}
// 开始新的一轮之前,清除原来的interval
clearInterval(time);
time = setInterval(function () {
axios({
proxy: proxies[index],
method: 'post',
url: 'http://vote.cyzone.cn/api/v1/vote/submit',
data: {
id: 575,
act_id: 11
}
})
.then(function(response){
console.log(i++,'成功',response.data.msg);
if (response.data.msg == "该IP段不再允许对该活动投票" || response.data.msg == "请求参数不合法" || !response.data.msg) {
index++;
}
errTotal = 0;
testIPIsNull();
})
.catch(function(error){
errTotal++;
console.log('失败', error.data, errTotal);
if (errTotal>15) {
index++;
errTotal = 0;
console.log('换')
}
testIPIsNull();
})
},200);
};
main(random());