Skip to content

Instantly share code, notes, and snippets.

@scripting
Created April 18, 2018 16:06
Show Gist options
  • Save scripting/3d1983a13119118173457876353ac030 to your computer and use it in GitHub Desktop.
Save scripting/3d1983a13119118173457876353ac030 to your computer and use it in GitHub Desktop.
This is the code that doesn't work. Helllp.
const iconv = require ("iconv-lite");
const request = require ("request");
const utils = require ("daveutils");
var feedUrl = "https://www.presseportal.de/rss/dienststelle_110972.rss2";
function getCharset (httpResponse) {
var contentType = httpResponse.headers ["content-type"];
if (contentType !== undefined) {
var encoding = utils.trimWhitespace (utils.stringNthField (contentType, ";", 2));
if (encoding.length > 0) {
var charset = utils.trimWhitespace (utils.stringNthField (encoding, "=", 2));
console.log ("getCharset: charset == " + charset);
return (charset);
}
}
return (undefined); //no charset specified
}
request (feedUrl, function (err, response, theString) {
if (err) {
console.log (err.message);
}
else {
if (response.statusCode != 200) {
console.log (response.statusCode);
}
else {
var theCharset = getCharset (response);
console.log (theCharset);
var theBuffer = Buffer.from (theString, "utf8");
var s = iconv.decode (theBuffer, theCharset);
console.log (s);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment