在chrome的控制台中粘贴并运行如下代码:
(function(console) { console.save = function(data, filename) { if (!data) { console.error('Console.save: No data') return; } if (!filename) filename = 'console.json' if (typeof data === 'object') { data = JSON.stringify(data, undefined, 4) } var blob = new Blob([data], { type: 'text/json' }), e = document.createEvent('MouseEvents'), a = document.createElement('a') a.download = filename a.href = window.URL.createObjectURL(blob) a.dataset.downloadurl = ['text/json', a.download, a.href].join(':') e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) a.dispatchEvent(e) } return 'success' })(console)
使用范例:
然后运行如下代码:
fetch('https://feed.sina.com.cn/api/roll/get?pageid=121&lid=1356&num=20&versionNumber=1.2.4&page=125&encode=utf-8&_=1600564853163') .then(res=>{ res.json().then(r=>{ console.save(r, 'result.json') }) });