Phantomjs: Phantomjs kann nicht anzeigen – oder einige andere UTF-8-Wörter.

Erstellt am 16. März 2014  ·  3Kommentare  ·  Quelle: ariya/phantomjs

Ich schreibe eine url2src.js, um eine HTML-Datei in eine andere HTML-Datei zu konvertieren, in der alle Javascripts verarbeitet werden.
Ich habe festgestellt, dass das Ergebnis nicht korrekt ist, wenn einige UTF-8-Wörter (wie -) vorhanden sind.

Ich verwende die chinesische Version von Windows 8.1. und führen Sie diesen Befehl in Windows cmd aus:

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

Der Inhalt von url2src.js ist:

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();
});

Genauere Informationen finden Sie hier im Anhang:
https://groups.google.com/forum/#!topic/phantomjs/oqvK8mkk6aY

Jede Hilfe wird geschätzt.

Hilfreichster Kommentar

Ich kenne den Grund jetzt, weil das Eingabe-HTML-Dokument standardmäßig als ISO-8859-1 behandelt wurde.
Das Hinzufügen von Meta zu set charset=utf-8 kann dieses Problem lösen.

<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>

Alle 3 Kommentare

Ich kenne den Grund jetzt, weil das Eingabe-HTML-Dokument standardmäßig als ISO-8859-1 behandelt wurde.
Das Hinzufügen von Meta zu set charset=utf-8 kann dieses Problem lösen.

<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>

Sie haben Recht. Allerdings kann ich die HTML, die mir andere Leute geben, nicht ändern.

Ich habe einige Dokumente, die keine Header-Informationen enthalten (ich bekomme sie von Apps von Drittanbietern) ... eine Möglichkeit, die Codierung zu erzwingen, wäre schön.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen