将chrome页面的变量保存到本地
在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')
})
});
谢谢您的来访,欢迎关注交流!以下是我的个人联系方式
电子邮箱:spring.wind2006@163.com,QQ:402085437,微信号:tm402085437

浙公网安备 33010602011771号