I am downloading page from web in node.js using standard request
library and the czech characters are not processed correctly.
I have tried utf-8
, ISO-8859-1
, latin1
, latin2
and few others encoding that was suggested by some other page but nothing works.
This is the code I am using:
const request = require("request-promise-native");
const iconv = require("iconv-lite");
async function run() {
const data = await request({
encoding: null,
method: "GET",
uri: "yourpage.com"
});
const body = iconv.decode(data, "ISO-8859-1");
console.log(body);
}
run().catch(console.log);
some of the czech pages are encoded in cp1250
, try it and it should work if all other encoding failed.
const request = require("request-promise-native");
const iconv = require("iconv-lite");
async function run() {
const data = await request({
encoding: null,
method: "GET",
uri: "yourpage.com"
});
const body = iconv.decode(data, "cp1250");
console.log(body);
}
run().catch(console.log);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.