check-du-task.js
1.54 KB
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
const rp = require('request-promise');
const ddAlert = require('../libs/dingding-alert');
const {logger} = require('../libs/logger');
const REG_CHECK = /="(\d\.\d\.\d)"/;
const version = '4.4.0';
const matchHtml = async(tick = 1) => {
const html = await rp({
url: 'https://m.poizon.com/mdu/product/detail.html?id=20&source=shareDetail',
gzip: true,
headers: {
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ig;q=0.7',
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
'upgrade-insecure-requests': 1
}
});
const match = html.match(REG_CHECK);
if (match || tick >= 3) {
return match;
}
return new Promise(r => {
setTimeout(() => {
r(matchHtml(tick + 1));
}, 2000);
});
};
module.exports = async() => {
const match = await matchHtml();
if (!match || match[1] !== version) {
if (!match) {
logger.info('[check-du-task] 未查询到version');
ddAlert('【爬虫-毒页面检测】未查询到version @18752098068');
return;
}
logger.info(`[check-du-task] 页面版本发生变化,应该为:${version},实际为:${match[1]}`);
ddAlert(`【爬虫-毒页面检测】毒页面接口版本发生变化,应该为:${version},实际为:${match[1]} @18752098068`);
return;
}
logger.info('[check-du-task] pass');
};