config.js
export const cookieStr =
'WTSESSIONID=155f7788cc3dcbae54a007a35e91.crm-web-wt-g2-srv15; BOMC_PROBE_ID=FB4D90E3F77ADE943B223DB764052EBE222EB5EEA83909F3638B33CAE7BAE24A16F0279702DAE09C10437EF951E404453592C33E34F5FC6E502D555F2A522423; currentBusiHref=; currentBusiName=; jumpCurrentBusiHref=; jumpCurrentBusiName=; operator=51811568; operorg=¹óÖÝά´´Ã³Ò×ÓÐÏÞ¹«Ë¾; operpost=¹óÖÝά´´Ã³Ò×ÓÐÏÞ¹«Ë¾-·Ç×Ô°ìÌü¸Úλ; crmCity=¹óÑô; crmCounty=ÄÏÃ÷Çø; moduleName=yhhdjycx; bussinessStep=21; sstcms=54549.36505.57775.0000; UBmobile=15285910184; scanEquipmentProvider=; AIPortal_SessionId=DATAcbe0795b-4bf0-427e-88be-5c0bf35a1e95; AIPortal_Oper_LastAccessedTime=509b07479765844476b1612561c5cf50; AIPortal_Oper_ActiveUrl=9b639d8e726a75a11ac8bad9de83ff4c0e5b0663fc25db5310eb2faf1abb70a2; AIPortal_HostIp=797ebb1dbeadc2a0d2a0082250895e40; AIPortal_Port=e31d5367c32b3700; AIPortal_Oper_OpId=3485eb4a193ffe9037feea805bed6525; AIPortal_Oper_OrgId=537d5b2b91ea711937feea805bed6525; AIPortal_Oper_OpName=f6032b4a1737c499; AIPortal_Oper_LogName=3485eb4a193ffe9037feea805bed6525; AIPortal_Oper_HostIp=c6f2c566ec25cee528faa51c22201a74; AIPortal_Result=c0012bc3eb72ee8a; AIPortal_Context_Path=37feea805bed6525; AIPortal_MAC=37feea805bed6525; AIPortal_CNAME=37feea805bed6525; AIPortal_4A_Session_Id=97bbe3d82a172311d94e254e3f9de22f; AIPortal_Region_Id=6678d3f66677bafa; AIPortal_Res_Id=fed357c6bcf1dce5; AIPortal_Station_Id=37feea805bed6525; cname=37feea805bed6525; mac=37feea805bed6525; ngboss_options=75fe019adbfd06c5a8ced660faae92beaab1ba62a2271775925bdbe50596b43d; WT_FPC=id=2a484f612d3a6160fc11647046935270:lv=1653316671923:ss=1653309241177; Distributed_OperId=51811568; WTSESSIONID=c422c52c4b234739782d49d52e5a.crm-web-wt-g2-srv8; AIPortal_SessionId=DATAcbe0795b-4bf0-427e-88be-5c0bf35a1e95; AIPortal_4A_Session_Id=e56e7cfd8c3f77553521b07937a3c089';
export const _dateTimeToken =
'FB4D90E3F77ADE943B223DB764052EBE71292EC8DC3C13940BDB41A6840B99282A3B05F0E04B517D53C899375FC1CCF0246DDF4B7F1FEBCC5B69F889262572B03013D1D2761B39A4';
file.js
var mockdata = require('./mockdata'); var fs = require('fs'); // 入参 fmt-格式 Date.prototype.format = function (fmt) { var o = { 'M+': this.getMonth() + 1, //月份 'd+': this.getDate(), //日 'h+': this.getHours(), //小时 'm+': this.getMinutes(), //分 's+': this.getSeconds(), //秒 'q+': Math.floor((this.getMonth() + 3) / 3), //季度 S: this.getMilliseconds(), //毫秒 }; if (/(y+)/.test(fmt)) { fmt = fmt.replace( RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length) ); } for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace( RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length) ); } } return fmt; }; function generateResult(data) { let fileName = new Date().format('yyyyMMddhhmmss') + '.xls'; var writeStream = fs.createWriteStream(fileName, { encoding: 'utf8' }); try { // var header = 'Sl No' + '\t' + ' Age' + '\t' + 'Name' + '\n'; // var row1 = '0' + '\t' + ' 21' + '\t' + 'Rob' + '\n'; // var row2 = '1' + '\t' + ' 22' + '\t' + 'bob' + '\n'; let data = mockdata.mockdata1; let row = ''; if (data.length > 0) { for (let i = 0; i < data.length; i++) { // row = ` ${data[i][0].toString()} \t ${data[i][1]}\n`; row = data[i].join('\t') + '\n'; writeStream.write(row); } } console.log('export excel successfully.'); } catch (error) { console.log('export excel failure.'); } finally { writeStream.close(); } } generateResult(); // 1. 使用fs模块 // var fs = require("fs"); // 2. 读取 // fs.readFile("test.txt", 'utf-8', (err, data) => { // if (err) throw err; // console.log(data) // }); // 3. 写入 // fs.writeFile("test.txt", "我写入了一句话", (err, data) => { // if (err) throw err; // }); // 4. 追加 // fs.appendFile("test.txt", "我写入了一句话", (err, data) => { // if (err) throw err; // });
helper.js
function typeObj(obj) { return Object.prototype.toString.call(obj).slice(8, -1) === 'Object'; } function typeArr(obj) { return Object.prototype.toString.call(obj).slice(8, -1) === 'Array'; } export function qs(data, flag) { var str = '', originData, encodeData; for (var i in data) { if (data.hasOwnProperty(i)) { originData = data[i]; if (typeObj(originData) || typeArr(originData)) { str += qs(originData, i); } else { encodeData = encodeURIComponent(originData); if (typeObj(data) && flag) { str += `${flag}[${i}]=${encodeData}&`; } else if (typeArr(data) && flag) { str += `${flag}[${i}]=${encodeData}&`; // str += `${flag}=${encodeData}&` } else { if (str.length > 0 && str[str.length - 1] !== '&') str += '&'; str += `${i}=${encodeData}&`; } } } } return str[str.length - 1] === '&' ? str.slice(0, -1) : str; } export async function getPhones() { return new Promise((res, rej) => { require('fs').readFile('phone.txt', 'utf-8', (err, data) => { if (err) { console.log(err); res([]); throw err; } else { res(Array.from(new Set(data.split('\n')))); } }); }); }
index.js
(async function () { const url = 'http://wt.crm.gz.cmcc/ecrm/qryactivityplentyinfouser/QryActivityPlentyinfoUserAction/qryBussinessInfoTable.menu'; var http = require('http'); var helper = require('./helper'); var config = require('./config'); /** * 15885689722 */ function getData(phone) { var body = { _buttonId: 'infoList-query', _dateTimeToken: config._dateTimeToken, _menuId: 110040000014, _tmpDate: 1653325156716, _zoneId: 'list-container', BillId: phone, is_first_render: true, }; let bodyStr = helper.qs(body); // var data = JSON.stringify(body); // data = // 'BillId=15885689722&iPage=&is_first_render=true&_zoneId=list-container&_tmpDate=1653331508838&_menuId=110040000014&_buttonId=infoList-query&_dateTimeToken=FB4D90E3F77ADE943B223DB764052EBE71292EC8DC3C13940BDB41A6840B99282A3B05F0E04B517D53C899375FC1CCF0246DDF4B7F1FEBCC5B69F889262572B03013D1D2761B39A4'; // console.log(data.length); //tp 头部 var headers = { Referer: 'http://wt.crm.gz.cmcc/crm/yhhdjycx.jsp?_busi_tab_iframe=true', 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)', Cookie: config.cookieStr, 'content-type': 'application/x-www-form-urlencoded', 'Accept-Encoding': 'gzip, deflate', 'Content-Length': bodyStr.length, }; //用与发送的参数类型 // var options = { // host: 'wt.crm.gz.cmcc', //ip // // port: 80, //port // path: '/ecrm/qryactivityplentyinfouser/QryActivityPlentyinfoUserAction/qryBussinessInfoTable.menu', //get方式使用的地址 // method: 'POST', //get方式或post方式 // headers: headers, // }; var options = { host: '127.0.0.1', //ip port: 8888, //port path: url, method: 'POST', //get方式或post方式 headers: headers, }; var req = http.request(options, function (res) { res.setEncoding('utf-8'); var html = ''; res.on('data', function (data) { html += data; }); res.on('end', function () { //这里接收的参数是字符串形式,需要格式化成json格式使用 // var resultObject = JSON.parse(html); // console.log('-----resBody-----', resultObject); console.log(html); // callBackFunction(html); }); req.on('error', function (e) { // TODO: handle error. console.log('-----error-------', e); }); }); req.write(bodyStr); req.end(); } let phones = await helper.getPhones(); if (phones.length == 0) { console.log('no phone data'); return; } else { getData('15885689722'); } })();
phone.txt
15885689722 | |
15885689722 | |
15885689722 | |
15885689723 |
// (async function () { // var fs = require('fs'); // async function getPhones() { // return new Promise((res, rej) => { // fs.readFile('phone.txt', 'utf-8', (err, data) => { // if (err) { // console.log(err); // throw err; // } else { // res(Array.from(new Set(data.split('\n')))); // } // }); // }); // } // debugger; // let p = await getPhones(); // console.log(p); // })(); // var mockdata = require('./config'); // (function () { // var config = require('./mockdata'); // console.log(config); // })(); // var $ = require('./jquery'); let { parse } = require('node-html-parser'); let html = `<!-- 竣工订单详情页面 --> <div class="fn-clear"> <h4 class="ui-color-middle-blue fn-left ui-busi-title">活动列表</h4> </div> <div id="custBillDetailInfo1"> <div class="fn-clear ui-mt-10 ui-ml-15 ui-mr-15"> <div class="table-responsive"> <div class="ui-table-nowrap ui-table-nowrap"> <table class="table table-bordered"> <tbody> <thead class="ui-bg-light-grey ui-color-deep-grey"> <tr> <th>类型</th> <th>策划名称</th> <th>策划ID</th> <th>生效时间</th> <th>失效时间</th> </tr> </thead> <tr class="thisRevoke ui-bg-light-blue "> <td>90元话费券</td> <td>90元话费券</td> <td class="thisOfferId">310000403710</td> <td>2022-05-06 00:04:34</td> <td>2022-06-01 00:00:00</td> </tr> <tr class="thisRevoke ui-bg-light-blue "> <td>全家包升级5G资费档-新</td> <td>全家包升级5G资费档-新</td> <td class="thisOfferId">310000576904</td> <td>2021-09-23 10:56:04</td> <td>2023-09-01 00:00:00</td> </tr> <tr class="thisRevoke ui-bg-light-blue "> <td>副卡方案优惠活动20GB(次月生效)-24个月</td> <td>副卡方案优惠活动20GB(次月生效)-24个月</td> <td class="thisOfferId">310000518302</td> <td>2021-09-23 13:28:26</td> <td>2023-09-01 00:00:00</td> </tr> <tr class="thisRevoke ui-bg-light-blue "> <td>家庭终端优惠购20元档</td> <td>家庭终端优惠购20元档</td> <td class="thisOfferId">310000521702</td> <td>2021-09-23 10:55:38</td> <td>2023-09-01 00:00:00</td> </tr> <tr class="thisRevoke ui-bg-light-blue "> <td>20元话费券</td> <td>20元话费券</td> <td class="thisOfferId">313310007201</td> <td>2022-05-01 16:00:56</td> <td>2022-06-01 00:00:00</td> </tr> </tbody> </table> </div> </div> <div id="detail_page" style="clear: both; float: right"> <div class='ui-paging'> <a href='javascript:void(0);' class='ui-button ui-button-sdisable'> <span class='glyphicon glyphicon-chevron-left'></span>上一页 </a> <a href='javascript:void(0);' onclick='AI.Ui.toLinkPage("linkType",5,"iPage",1,"iPara","","list-container","query-form","/ecrm/qryactivityplentyinfouser/QryActivityPlentyinfoUserAction/qryBussinessInfoTable.menu")' class='ui-paging-item ui-paging-current'>1</a> <a href='javascript:void(0);' onclick='AI.Ui.toLinkPage("linkType",5,"iPage",2,"iPara","","list-container","query-form","/ecrm/qryactivityplentyinfouser/QryActivityPlentyinfoUserAction/qryBussinessInfoTable.menu")' class='ui-paging-item'>2</a> <a href='javascript:void(0);' onclick='AI.Ui.toLinkPage("linkType",3,"iPage",1,"iPara","","list-container","query-form","/ecrm/qryactivityplentyinfouser/QryActivityPlentyinfoUserAction/qryBussinessInfoTable.menu")' class='ui-button ui-button-swhite'> 下一页<span class='glyphicon glyphicon-chevron-right'></span> </a> <span class='ui-paging-info'><span class='ui-paging-bold'>1/2</span>页,共9条</span> <span class='ui-paging-which'><input name='iPage' type='text'></span> <a class='ui-paging-info ui-paging-goto' href='javascript:void(0);' onclick='AI.Ui.toLinkPage("linkType",5,"iPage",2,"iPara","","list-container","query-form","/ecrm/qryactivityplentyinfouser/QryActivityPlentyinfoUserAction/qryBussinessInfoTable.menu",2)'>跳转</a> </div> </div> </div> </div> <div id="revokeDiv"></div> <script type="text/javascript"> $(function () { $(".thisRevoke").click(function () { $(this).siblings(".ui-bg-middle-grey").removeClass("ui-bg-middle-grey"); $(this).addClass("ui-bg-middle-grey"); var OfferId = $(this).find(".thisOfferId").html(); var data = { "OfferId": OfferId }; var url = _curActionUrlFull + '/queryDetailInfo.menu'; AI.Ajax.post(url, "revokeDiv", "", data, "", function (isSuccess) { if (isSuccess) { } } ); }); }); </script>`; (function () { // console.time('parse time'); const doc = parse(html); // console.timeEnd('parse time'); let tcStrs = doc .querySelectorAll('tr td:nth-child(1)') .map((i) => i.innerText) .join(','); console.log(tcStrs, 'tcStrs'); let totalPageStr = doc.querySelector('.ui-paging-bold').innerText; let totalPage = 1; if (totalPageStr.includes('/')) { totalPage = totalPageStr.split('/')[1]; } if(totalPage>1){ } console.log(totalPage, 'totalPage'); })();
第一页
BillId=15885689726&linkType=&iPara=&iPage=&is_first_render=true&_zoneId=list-container&_tmpDate=1653504179098&_menuId=110040000014&_buttonId=infoList-query&_dateTimeToken=FB4D90E3F77ADE943B223DB764052EBE71292EC8DC3C13940BDB41A6840B99284BE31CA7789AF7A2EE5E2AD1AB6C520CB61BF3F692E095711E377EFDBAFAC3B85E833772767A1C1D
第二页
BillId=15885514864&linkType=&iPara=&iPage=&is_first_render=true&_zoneId=list-container&_tmpDate=1653503861474&_menuId=110040000014&_buttonId=infoList-query&_dateTimeToken=FB4D90E3F77ADE943B223DB764052EBE71292EC8DC3C13940BDB41A6840B99284BE31CA7789AF7A2EE5E2AD1AB6C520CB61BF3F692E095711E377EFDBAFAC3B85E833772767A1C1D