简体   繁体   English

如何从Android中的URL获取页面的HTML源代码?

[英]How to get the html-source of a page from an url in android?

I know this question has already been asked before but the solutions doesn't work or are deprecated.. 我知道之前已经有人问过这个问题,但是解决方案不起作用或不建议使用。

So, I want get the html code of a webpage in android in java, if somebody can help me.. 所以,如果有人可以帮助我,我想在Java中获取android网页的html代码。

use webview to load url in your app then use the following code to get the html 使用webview在应用程序中加载url,然后使用以下代码获取html

wvbrowser.evaluateJavascript(
        "(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
         new ValueCallback<String>() {
            @Override
            public void onReceiveValue(String html) {
                Log.d("HTML", html); 
                // code here
            }
    });

taken from 采取

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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