-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbtest.js
230 lines (209 loc) · 11.1 KB
/
btest.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
const puppeteer = require('puppeteer');
const fs = require('fs');
const username = "xxxxx";
const password = 'xxxxxx';
(async () => {
const browser = await puppeteer.launch({executablePath: './bin/chrome-win32/chrome.exe',headless: true});
const page = await browser.newPage();
await page.goto('https://bihu.com/login', {waitUntil: 'networkidle2'});
const loginUser = "#loginName";
const loginPassword = "#password";
const loginButton = "div.login.container .ipt-public form > div.btn-box > button";
await page.click(loginUser);
await page.type(loginUser, username);
await page.click(loginPassword);
await page.type(loginPassword, password);
await page.click(loginButton);
await page.waitForSelector('.alt-item');
while(true){
var now = new Date();
var end = new Date(now.getFullYear(),now.getMonth(),now.getDate(),23).getTime();
var start = new Date(now.getFullYear(),now.getMonth(),now.getDate(),6).getTime();
now = now.getTime();
if(now > start && now < end){
try{
await page.goto('https://bihu.com/?category=follow');
await page.waitForSelector('.alt-item');
await page.waitFor(10 * 1000);
const data = await page.evaluate((user) => {
var titleDom = document.querySelector('.alt-item .alt-box .alt-content .content1');
var title = titleDom.innerHTML;
var clickZan = false;
var zan = document.querySelector('.alt-item .alt-box .alt-bottom-item:nth-child(2)');
if(zan.classList.contains('active')){
clickZan = true;
}
var p = document.querySelector('.alt-item .alt-name > p:nth-child(2)').innerHTML;
var myDate = new Date();
myDate.toLocaleString( );
var zanNum = document.querySelector('.alt-item .alt-box .alt-bottom-item:nth-child(2) span').innerText;
var info = myDate + ",用户:" + user + ",文章:" + title + ", 时间:" + p + ", 是否点过赞:" + clickZan;
if(clickZan || zanNum > 300){
info += ", 点赞人数:" + zanNum;
return {info: info};
}
if(p.indexOf('秒') >= 0){
zan.click();
function like(test){
var xmlhttp=new XMLHttpRequest();
var t = localStorage["ANDUI_BIHU_LOGININFO"];
var e = JSON.parse(t);
var userId = e.userId;
var access = e.accessToken;
var d = JSON.parse(test);
var artId = d.data.artList.list[0].id;
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
console.log(xmlhttp.responseText)
}
}
xmlhttp.open("POST","https://be02.bihu.com/bihube-pc/api/content/upVote",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
var param = 'userId='+userId+'&accessToken='+access+'&artId=' + artId;
xmlhttp.send(param);
}
function log(test){
var c = 0;
var cI = setInterval(function(){
if(c >= 2){
clearInterval(cI);
}
like(test);
c++;
}, 30000);
}
function getList(callback){
var xmlhttp=new XMLHttpRequest();
var t = localStorage["ANDUI_BIHU_LOGININFO"];
var e = JSON.parse(t);
var userId = e.userId;
var access = e.accessToken;
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
callback.apply(this, [xmlhttp.responseText]);
}
}
xmlhttp.open("POST","https://be02.bihu.com/bihube-pc/api/content/show/getFollowArtList",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
var param = 'userId='+userId+'&accessToken='+access;
xmlhttp.send(param);
}
getList(log);
}
var index = p.indexOf('分钟');
// 只点赞20分钟内的文章
if(index >= 0 && !clickZan){
var min = p.substring(0, index);
if(parseInt(min) < 10){
zan.click();
function like(test){
var xmlhttp=new XMLHttpRequest();
var t = localStorage["ANDUI_BIHU_LOGININFO"];
var e = JSON.parse(t);
var userId = e.userId;
var access = e.accessToken;
var d = JSON.parse(test);
var artId = d.data.artList.list[0].id
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
console.log(xmlhttp.responseText)
}
}
xmlhttp.open("POST","https://be02.bihu.com/bihube-pc/api/content/upVote",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
var param = 'userId='+userId+'&accessToken='+access+'&artId=' + artId;
xmlhttp.send(param);
}
function log(test){
var c = 0;
var cI = setInterval(function(){
if(c >= 2){
clearInterval(cI);
}
like(test);
c++;
}, 30000);
}
function getList(callback){
var xmlhttp=new XMLHttpRequest();
var t = localStorage["ANDUI_BIHU_LOGININFO"];
var e = JSON.parse(t);
var userId = e.userId;
var access = e.accessToken;
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
callback.apply(this, [xmlhttp.responseText]);
}
}
xmlhttp.open("POST","https://be02.bihu.com/bihube-pc/api/content/show/getFollowArtList",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=utf-8");
var param = 'userId='+userId+'&accessToken='+access;
xmlhttp.send(param);
}
getList(log);
}
}
info += ", 点赞人数:" + zanNum;
info += ", 自动点赞:" + clickZan;
return {info: info, clicked: clickZan};
},username);
if(data.clicked){
fs.appendFileSync('zanlog.txt', data.info + "\n");
}
console.log(data.info);
}catch(e){
console.log('出错了, 重新登录');
await page.goto('https://bihu.com/login', {waitUntil: 'networkidle2'});
await page.reload({waitUntil: 'networkidle2'});
await page.waitFor(60*1000);
const isLogin = await page.evaluate(()=>{
var loginHeader = document.querySelector('.login-header');
if(loginHeader){
return true;
}
return false;
});
if( isLogin){
console.log('在登录页,重新登录');
await page.click(loginUser);
await page.type(loginUser, username);
await page.click(loginPassword);
await page.type(loginPassword, password);
await page.click(loginButton);
var unLogin = true;
var loginTry = 0;
while(unLogin && loginTry < 50){
console.log("重试登录:" + loginTry);
const logined = await page.evaluate(()=>{
var loginHeader = document.querySelector('.login-header');
if(loginHeader){
return true;
}
return false;
});
unLogin = logined;
loginTry++;
if(unLogin){
await page.goto('https://bihu.com/login', {waitUntil: 'networkidle2'});
await page.waitFor(60*1000);
await page.click(loginUser);
await page.type(loginUser, username);
await page.click(loginPassword);
await page.type(loginPassword, password);
await page.click(loginButton);
await page.waitFor(1000);
}
}
await page.waitForSelector('.alt-item');
}
}
// 等待1分钟
await page.waitFor(120*1000);
}else {
// 每隔10分钟刷新下
await page.waitFor(600*1000);
await page.goto('https://bihu.com/', {waitUntil: 'networkidle2'});
}
}
})();