I am not sure how far this is going to be helpful. But I have used the below snippet to fetch a small html page's data. I hope it helps you.
Create a class like the one below,
class MyJavaScriptInterface
{
@SuppressWarnings("unused")
public void processHTML(final String html)
{
Log.i("processed html",html);
Thread OauthFetcher=new Thread(new Runnable() {
@Override
public void run() {
String oAuthDetails=null;
oAuthDetails=Html.fromHtml(html).toString();
Log.i("oAuthDetails",oAuthDetails);
}
});OauthFetcher.start();
}
}
Now in your onCreate(),
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
webview.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, final String url) {
String oAuthUrl=getString("www.google.com");
if(url.contains(oAuthUrl))
{
Log.i("Contains","Auth URL");
twitter_webview.loadUrl("javascript:window.HTMLOUT.processHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
}
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressDialog.show();
}
});
And now what happens is that, when your page finishes loading, the JavaScript class will be called, which would retrieve the page source and store it in a String as your requirement.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…