我只是使用请求承诺抓取了中文html,将其编码为无,返回缓冲区并使用fs
模块保存。
const data = await requestPromise({
proxy,
strictSSL: false,
uri: url,
encoding: null,
timeout: 20 * 1000,
});
fs.writeFileSync('china.html',data)
当我打开china.html时,它会正确打开,显示在此链接上找到的html代码:
https://jsbin.com/texohosopa/1/edit?html
但是当我使用fs.readFileSync(china.txt)
从nodejs读取同一文件时,它会返回如下垃圾:
在此链接https://jsbin.com/xuparujeho/1/edit?html
中(由于粘贴中文时出错,因此无法在stackoverflow上发布)
应该是节点问题,因为该html页面在chrome上运行良好,但在nodejs上运行不正常。