java中使用WebView提取指定网页的HTML内容

Java中使用WebView提取指定网页的HTML内容

关键是要在网页加载完毕的时候获取HTML源文本


[java]  view plain  copy
  1. //抓取网页文本内容  
  2.         webEngine.getLoadWorker().stateProperty()  
  3.                 .addListener(new ChangeListener() {  
  4.                     @Override  
  5.                     public void changed(ObservableValueextends State> ov,  
  6.                             State oldState, State newState) {  
  7.                         if (newState == State.SUCCEEDED) {//State.SUCCEEDED  
  8.                             Document doc = webEngine.getDocument();  
  9.                             String docContent = doc.getDocumentElement().getTextContent();  
  10.                             System.out.println(docContent);  
  11.                             long htmlLength=docContent.length();  
  12.                             informationLabel.setText(htmlLength+"");  
  13.                         }  
  14.                     }  
  15.                 });  

你可能感兴趣的:(java)