我想抢先获取要在中加载的网页的HTML代码,webView使用正则表达式解析它,并仅显示所需的HTML代码,同时让该网页仍然认为它已加载了所有内容。
有什么方法可以通过WebViewClient.onLoadResource()或类似方法来做到这一点?
编辑:我尝试过此:
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('
'+document.getElementsByTagName('html')[0].innerHTML+'');");Pattern pattern = Pattern.compile("