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
| const request = require('request') const { JSDOM } = require('jsdom') const fs = require('fs')
let dataArr = [] let type = '大乐透';
function init(url){ request(url,(err,res,body)=>{ if(res.statusCode == 200){ console.log('请求页面成功!'); const dom = new JSDOM(body) const document = dom.window.document; const tbody = document.querySelectorAll('#tdata')[0].querySelectorAll('tr') console.log('格式转换中...'); tbody.forEach((v,i)=>{ dataArr[i] = [] v.querySelectorAll('td').forEach((w,j)=>{ dataArr[i][j] = w.innerHTML }) }) fs.writeFile(`./${type}.json`,JSON.stringify(dataArr),function(err){ if(!err){ console.log('保存成功!'); } }) }else{ console.log('页面请求失败!'); } }) } let dlt = 'http://datachart.500.com/dlt/history/newinc/history.php?limit=200000&sort=0' let ssq = 'http://datachart.500.com/ssq/history/newinc/history.php?limit=200000&sort=0' init(type == '双色球' ? ssq : dlt)
|