I write a url2src.js to convert a html file to another html file that all javascripts are processed.
I found if there is some UTF-8 words(such as —), the result is not correct.
I use Windows 8.1 Chinese version. and run this command in windows cmd:
d:\epub\components>phantomjs --output-encoding=utf8 --script-encoding=utf8 url2src.js activities2.html activities2-processed.html
d:\epub\components>phantomjs --version
1.9.7
url2src.js's content is:
var page = require('webpage').create(),
system = require('system'),
t, address, output;
if (system.args.length !== 3) {
console.log('Usage: url2src.js <some URL> <output File path>');
phantom.exit();
}
t = Date.now();
address = system.args[1];
output = system.args[2];
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address : ' + address);
} else {
t = Date.now() - t;
//console.log('Loading time ' + t + ' ms');
var js = page.evaluate(function () {
return document;
});
//console.log(js.all[0].outerHTML);
var fs = require('fs');
try {
fs.write(output, js.all[0].outerHTML, 'w');
} catch(e) {
console.log(e);
}
}
phantom.exit();
});
More detail info is in the attachment here:
https://groups.google.com/forum/#!topic/phantomjs/oqvK8mkk6aY
Any help is appreciated.
I know the reason now, because the input html document was treated as ISO-8859-1 as default.
Add meta to set charset=utf-8 can solve this problem.
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p> The user interface for an activity is provided by a hierarchy of views—objects derived from the <code>View</code> class. </p>
</body>
</html>
You are right.However, I can not change the html which other people give to me.How to do?
I have some documents that don't have any header information (I'm getting them from third party apps)... a way to force the encoding would be nice.
Most helpful comment
I know the reason now, because the input html document was treated as ISO-8859-1 as default.
Add meta to set charset=utf-8 can solve this problem.