Created
April 30, 2021 13:02
-
-
Save mzdluo123/3e1529560ca0e2bba3a4ce76cd0da520 to your computer and use it in GitHub Desktop.
EPSDATA数据抓取
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 到数据查看界面选择好要查看的数据和时间 | |
| 按下f12粘贴下面的代码然后回车 | |
| 点击查询即可自动下载数据为csv格式 | |
| */ | |
| (function() { | |
| function ajaxEventTrigger(event) { | |
| var ajaxEvent = new CustomEvent(event, { detail: this }); | |
| window.dispatchEvent(ajaxEvent); | |
| } | |
| var oldXHR = window.XMLHttpRequest; | |
| const BOM = '\uFEFF' | |
| function newXHR() { | |
| var realXHR = new oldXHR(); | |
| realXHR.addEventListener('load', function () { ajaxEventTrigger.call(this, 'ajaxLoad'); }, false); | |
| return realXHR; | |
| } | |
| window.XMLHttpRequest = newXHR; | |
| window.addEventListener('ajaxLoad', function (e) { | |
| const req = e.detail; | |
| if (req.status !== 200){ | |
| return; | |
| } | |
| if (req.responseURL.indexOf("/charts.do")!==-1){ | |
| const rsp = req.response; | |
| const jsData = JSON.parse(rsp); | |
| window.d = jsData | |
| console.log(jsData); | |
| const title = jsData.yNames; | |
| const name = "导出数据"; | |
| title.unshift("时间") | |
| const data = []; | |
| jsData.listData.forEach((i)=>{ | |
| var iData =i.vals | |
| iData.unshift(i.xName) | |
| data.push(i.vals) | |
| }) | |
| var output = title.join() + '\n'; | |
| data.forEach((i)=>{ | |
| output += i.join()+'\n'; | |
| }) | |
| console.log(data); | |
| console.log(output); | |
| var blob = new Blob([BOM + output], {type: 'text/csv'}) | |
| if (navigator.msSaveOrOpenBlob) { | |
| navigator.msSaveOrOpenBlob(blob, `${name}.csv`) | |
| } else { | |
| let downloadLink = document.createElement('a') | |
| downloadLink.setAttribute('href', URL.createObjectURL(blob)) | |
| downloadLink.download = `${name}.csv` | |
| document.body.appendChild(downloadLink) | |
| downloadLink.click() | |
| document.body.removeChild(downloadLink) | |
| } | |
| } | |
| } ); | |
| } | |
| )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment