fetch('http://tieba.baidu.com')
.then(res=> res.blob())
.then(blob => {
var reader = new FileReader();
reader.onload = function(e) {
var text = reader.result;
console.log(text)
}
reader.readAsText(blob, 'GBK')
})
参考:https://segmentfault.com/q/1010000004338890/
本文介绍了一种使用Fetch API从百度贴吧获取数据的方法,通过then方法链处理响应,将返回的blob类型数据转换为文本,并使用FileReader API进行读取。此过程涉及编码的指定,最终将读取到的数据输出到控制台。
6638

被折叠的 条评论
为什么被折叠?



