Comments (5)
I don't understand what you mean. node-iconv converts text from one character set to another, it doesn't do anything with HTML.
from node-iconv.
If you read Google ES with thiss;
request({ uri:'http://www.google.es' }, function (error, response, body) {
if (error && response.statusCode !== 200) {
console.log('Error when contacting google.com')
}
it is ISO-8859-1 encoding as you can see in the HTML which is returned by Google.
When I output the response straight away with
sys.puts(body);
It outputs normal HTML but the wrong characters, so I want to convert one char set into another, so I run;
iconv = new Iconv('ISO-8859-1', 'UTF-8');
body = iconv.convert(body);
when I then print
sys.puts(body)
All characters are encoded, for instance;
<textarea id="csi" style="display: none;"></textarea><div id="mngb"><div id="gb"><script>window.gbar&&gbar.eli&&gbar.eli()<
etc....
And the characters are not correct either after the convert.
Edit: I'll try to make some simple to reproduce it...
from node-iconv.
request({ uri:'http://www.google.es' }, function (error, response, body) {
if (error && response.statusCode !== 200) {
console.log('Error when contacting google.com')
}
iconv = new Iconv('ISO-8859-1', 'UTF-8');
body = iconv.convert(body);
I'll try to reproduce the html encoded characters as well, but the above does not fix the characters anyway, even though I think it's ISO-8859-1 to UTF-8; it still contains stuff like;
Google.es tambi�n en
Any idea what could be wrong?
Edit: php -r 'echo iconv("ISO-8859-1", "UTF-8", file_get_contents("http://www.google.es"));'
Does what is expected.
from node-iconv.
Ok, after a lot of searching and trying, I found that I have to use
_res = new Buffer(_res, 'binary');
var iconv = new Iconv(enc, 'UTF-8');
_res = iconv.convert(_res).toString('utf8');
That was incredibly unclear, but ok, it works ;)
from node-iconv.
Glad you got it solved.
from node-iconv.
Related Issues (20)
- npm install sqlite3 HOT 1
- cannot open shared object file HOT 2
- What about CHANGELOG.md HOT 5
- utf-8 to iso-8859-1 error no conversion HOT 2
- Fails to install on windows machine HOT 3
- Unable to install
- Unable to install HOT 3
- iconv cannot be used in worker threads HOT 5
- how to change "한글" to euc-kr ? HOT 1
- Can't resolve ~~ error while developing an Electron app HOT 1
- Memory leak when used with byline? HOT 2
- Upgrade node-gyp to remove python2 dependency HOT 1
- Can't convert string from ISO-8859-1 to windows-1251 HOT 3
- Encodings not supported HOT 2
- Any barriers to IBM500, 037 ? HOT 1
- not doing proper encoding HOT 5
- npm ERR! HOT 1
- WSL npm install iconv failing HOT 3
- will it work with nodejs 20? HOT 1
- NV21 failure? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-iconv.