url2src.js๋ฅผ ์์ฑํ์ฌ html ํ์ผ์ ๋ชจ๋ ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ์ฒ๋ฆฌ๋๋ ๋ค๋ฅธ html ํ์ผ๋ก ๋ณํํฉ๋๋ค.
์ผ๋ถ UTF-8 ๋จ์ด(์: โ)๊ฐ ์์ผ๋ฉด ๊ฒฐ๊ณผ๊ฐ ์ฌ๋ฐ๋ฅด์ง ์๋ค๋ ๊ฒ์ ์์์ต๋๋ค.
Windows 8.1 ์ค๊ตญ์ด ๋ฒ์ ์ ์ฌ์ฉํฉ๋๋ค. 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์ ๋ด์ฉ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
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();
});
์์ธํ ์ ๋ณด๋ ์ฌ๊ธฐ ์ฒจ๋ถ ํ์ผ์ ์์ต๋๋ค:
https://groups.google.com/forum/#!topic/phantomjs/oqvK8mkk6aY
๋์์ ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.
์
๋ ฅ๋ html ๋ฌธ์๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ISO-8859-1๋ก ์ทจ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด์ ๊ทธ ์ด์ ๋ฅผ ์์์ต๋๋ค.
๋ฉํ๋ฅผ ์ถ๊ฐํ์ฌ charset=utf-8๋ก ์ค์ ํ๋ฉด ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค.
<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>
๋น์ ๋ง์ด ๋ง์ต๋๋ค.ํ์ง๋ง ๋ค๋ฅธ ์ฌ๋๋ค์ด ๋์๊ฒ์ฃผ๋ html์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.์ด๋ป๊ฒํด์ผํฉ๋๊น?
ํค๋ ์ ๋ณด๊ฐ ์๋ ๋ฌธ์๊ฐ ์์ต๋๋ค(ํ์ฌ ์ฑ์์ ๊ฐ์ ธ์ด)... ์ธ์ฝ๋ฉ์ ๊ฐ์ ํ๋ ๋ฐฉ๋ฒ์ด ์ข์ ๊ฒ์ ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ ๋ ฅ๋ html ๋ฌธ์๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ISO-8859-1๋ก ์ทจ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด์ ๊ทธ ์ด์ ๋ฅผ ์์์ต๋๋ค.
๋ฉํ๋ฅผ ์ถ๊ฐํ์ฌ charset=utf-8๋ก ์ค์ ํ๋ฉด ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค.