在打开的页面加载框架中:
<iframe id="wikipedia" src="http://en.wikipedia.org"></iframe>
试图找到内容:
Document document = webEngine.getDocument();
Element elementById = document.getElementById("wikipedia");
System.out.println(elementById.getTextContent());
但是没有取得成果......
答案 0 :(得分:3)
以下代码适用于javafx2:
Document doc = webEngine.getDocument();
HTMLIFrameElement iframeElement = (HTMLIFrameElement) doc.getElementById("wikipedia");
Document iframeContentDoc = iframeElement.getContentDocument();
Element rootElement = iframeContentDoc.getDocumentElement();
System.out.println(rootElement.getTextContent());