title: Is it possible to get the HTML code from WebView
body: <p>I would like to preemptively get the HTML code of a webpage that is to be loaded in a <code>webView</code>, parse it using regex, and display only the HTML code that I want, while letting the webpage still think it has loaded everything. </p>
  
  <p>Is there any way to do that in the <code>WebViewClient.onLoadResource()</code> or similar methods?</p>
  
  <p>EDIT: I tried this:</p>
  
  <pre><code>class MyJavaScriptInterface  
   {  
        @SuppressWarnings("unused")  
           public void showHTML(String html, Context context)  
           {  
              new AlertDialog.Builder(context)  
                   .setTitle("HTML")  
                   .setMessage(html)  
                   .setPositiveButton(android.R.string.ok, null)  
               .setCancelable(false)  
               .create();  
                 pageHTML = html;
           }  
   }
  
  @Override
      public void customizeWebView(final ServiceCommunicableActivity activity, final WebView webview, final SearchResult mRom) {
          mRom.setFileSize(getFileSize(mRom.getURLSuffix()));
          webview.getSettings().setJavaScriptEnabled(true);
          MyJavaScriptInterface interfaceA = new MyJavaScriptInterface();
          webview.addJavascriptInterface(interfaceA, "HTMLOUT");  
          WebViewClient anchorWebViewClient = new WebViewClient()
          {
              @Override  
              public void onPageFinished(WebView view, String url)  
              {  
                  /* This call inject JavaScript into the page which just finished loading. */  
                  webview.loadUrl("javascript:window.HTMLOUT.showHTML('&lt;head&gt;'+document.getElementsByTagName('html')[0].innerHTML+'&lt;/head&gt;');");
                  Pattern pattern = Pattern.compile("&lt;h2&gt;Winning Sc.+&lt;/h2&gt;&lt;/div&gt;(.+)&lt;br&gt;", Pattern.DOTALL);
                  Matcher matcher = pattern.matcher(pageHTML);
                  matcher.find();
  </code></pre>
  
  <p>The interface is never called</p>