check-du-task.js 1.54 KB
const rp = require('request-promise');
const ddAlert = require('../libs/dingding-alert');
const {logger} = require('../libs/logger');
const REG_CHECK = /="(\d\.\d\.\d)"/;
const version = '3.5.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 @18661200251');
      return;
    }
    logger.info(`[check-du-task] 页面版本发生变化,应该为:${version},实际为:${match[1]}`);
    ddAlert(`【爬虫-毒页面检测】毒页面接口版本发生变化,应该为:${version},实际为:${match[1]} @18661200251`);
    return;
  }
  logger.info('[check-du-task] pass');
};