简体   繁体   中英

Extract HTML from a WebView

I want to extract only the Table (TagName: tbody) from the following Webpage: http://info.tam.ch/custom/stpl_klw.php

But it doesn't work. Can somebody help me?

(I used this Tutorial: http://lexandera.com/2009/01/extracting-html-from-a-webview/ )

I tried this:

public class Stundenplan extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Context myApp = this; 
    class MyJavaScriptInterface  
    {  
        @SuppressWarnings("unused")  
        public void showHTML(String html)  
        {  
            new AlertDialog.Builder(myApp)  
                .setTitle("HTML")  
                .setMessage(html)  
                .setPositiveButton(android.R.string.ok, null)  
            .setCancelable(false)  
            .create()  
            .show();  
        }  
    }  

    final WebView browser = (WebView)findViewById(R.id.webView);  
    browser.getSettings().setJavaScriptEnabled(true);  
    browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");  
    browser.setWebViewClient(new WebViewClient() {  
        @Override  
        public void onPageFinished(WebView view, String url)  
        {  
            browser.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('tbody')[0].innerHTML+'</head>');");  
        }  
    });  

    browser.loadUrl("http://info.tam.ch/custom/stpl_klw.php"); 
}

The html of the referenced page does not contain a <tbody> element. The Stundenplan is a normal <table> element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM