【问题标题】:Get data from text box of a website using WebView使用 WebView 从网站的文本框中获取数据
【发布时间】:2017-11-28 10:20:06
【问题描述】:

在我的应用程序中,我在 WebView 中展示了我们自己的电子商务网站。在那,我有用户名和密码文本框。我想在他输入时获取文本数据的用户名并将其存储在我的文件中。我无法控制网站(登录页面)。它完全由第三方构建我怎样才能做到这一点?请帮忙。 提前谢谢你。

【问题讨论】:

标签: android android-webview


【解决方案1】:

您可以使用 JavaScript 从 webView 加载数据。 我使用以下 JS 代码从 webView 加载 html JS_PARSER = "(function() { return ('&lt;html&gt;'+document.getElementsByTagName('html')[0].innerHTML+'&lt;/html&gt;'); })();" webview.getSettings().setJavaScriptEnabled(true); webView.evaluateJavascript(JS_PARSER, <callback for handle response with html>); evaluateJavascript docs

并尝试从 html 加载数据。

作为第二种方法,您可以使用 JS 函数从文本框加载文本。并为每个文本框执行函数。

从文本框加载数据的JS函数: function myFunction(){ return document.getElementById("f6").value; }

第二种方式的Android代码: String LOAD_FUN = function getValue(){ return document.getElementById('%s').value; }(); webView.evaluateJavascript(String.format(LOAD_FUN, "<String with textBoxId>"), <callback for handle textBox value>)

【讨论】:

  • 感谢您的回答。但我的问题是我无法控制网站(登录页面)。它完全由第三方构建。
  • 尝试执行,我的回答的第一种方式,并将html回复附加到帖子中,我会尽力帮助你。
猜你喜欢
  • 1970-01-01
  • 2017-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多