【问题标题】:Fetching any particular text from Webview从 Webview 获取任何特定文本
【发布时间】:2013-05-08 06:44:55
【问题描述】:

我是 android 的 webview 新手。我只想知道如果文本可用,我们如何从 webview 获取任何特定文本。

示例:我的 webview 上有一些文本,例如“Android 运行良好”,如果文本“Android”在 webview 上可用,那么我想执行其他操作。

if("Android" available on webview) {
then Print("It works great")
}
else {
Print ("Useless")
}

我如何在 Android 中达到同样的效果。 请帮帮我。 在此先感谢 :)

【问题讨论】:

标签: android uitableview android-layout webview android-webview


【解决方案1】:

这不是最好的方法,但您可以获取 url 内容,然后将其与您的文本进行比较

try {                   
                URL url;
                url = new URL("http://www.google.com/");

                BufferedReader in;

                in = new BufferedReader(new InputStreamReader(url.openStream()));                   

                String inputLine;
                while ((inputLine = in.readLine()) != null) {
                    if(inputLine.contains("Android")) {

                    } else {

                    }
                }
                in.close();

            } catch(Exception e) {                  
                e.printStackTrace();
            }

【讨论】:

  • 我在我的一个应用程序中尝试过它并且它工作正常,但是你需要在异步任务中运行它,否则你会得到一个networkingonuithread异常
猜你喜欢
  • 2012-03-23
  • 2016-06-26
  • 1970-01-01
  • 1970-01-01
  • 2014-03-04
  • 1970-01-01
  • 2022-06-15
  • 2019-11-20
  • 1970-01-01
相关资源
最近更新 更多