WebEngine.getDocument
戻りorg.w3c.dom.Document
、あなたのコードから判断期待しないでJavaScriptの文書を。
残念ながら、org.w3c.dom.Document
を印刷するにはかなりのコードが必要です。 What is the shortest way to pretty print a org.w3c.dom.Document to stdout?から解決策を試すことができます(下のコードを参照)。
Document
で作業する前に、ドキュメントが読み込まれるまで待つ必要があることに注意してください。 LoadWorker
が、ここで使用されている理由はここにある:
public void start(Stage primaryStage) {
WebView webview = new WebView();
final WebEngine webengine = webview.getEngine();
webengine.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
Document doc = webengine.getDocument();
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.transform(new DOMSource(doc),
new StreamResult(new OutputStreamWriter(System.out, "UTF-8")));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
webengine.load("http://stackoverflow.com");
primaryStage.setScene(new Scene(webview, 800, 800));
primaryStage.show();
}
サイトはHTML EXエラーがある場合は不足しているコンテンツを取得するあなたの方法:フィックス –