有没有办法在 Android 应用程序的 webview 中获取 HTML? [英] Is there a way to get the HTML in a webview in an Android app?
问题描述
有没有办法在 Android 应用程序的 web 视图中获取 HTML?我更喜欢通过简单的资源下载来获取 HTML,特别是如果我可以获取由 JavaScript 生成的 HTML.
Is there a way to get the HTML in a webview in an Android app? I would prefer this to getting the HTML via a simple resource download, especially if I can get HTML generated by JavaScript.
例如,如果我想要我的 android 应用程序(包括 gmail 等网络应用程序)可以访问的随机 HTML 文档中所有 URL 的列表,我该怎么做?
For example if I wanted a list of all URLs in a random HTML document accessible to my android application, including web apps such as gmail, how would I go about it?
android 文档警告让 JavaScript 访问应用程序,但我在想,如果可能的话,可能的解决方案是将一些 JavaScript 注入网页,然后以希望安全的方式与我的应用程序通信(通过消息在我控制 javascript 或类似内容的网站上通过 iframe 传递或其他内容).
The android documentation warns about letting JavaScript access the application, but I was thinking maybe a solution would be, if at all possible, to inject some JavaScript into the webpage which then communicates with my application in a hopefully safe way (via message passing or something through an iframe on a site that I control the javascript on or something similar).
有人有什么想法吗?
推荐答案
有没有办法在 Android 应用的 webview 中获取 HTML?
Is there a way to get the HTML in a webview in an Android app?
不容易.javascript:
URL 有效,并且 addJavascriptInterface()
允许您设置 Javascript 可以调用的回调.您可以创建由 javascript:
URL 加载的 Javascript 片段,该 URL 获取您的 DOM,或遍历您的链接列表,或通过您注册的回调对象将结果发送回您通过 addJavascriptInterface()
.
Not easily. javascript:
URLs work, and addJavascriptInterface()
allows you to set up callbacks that the Javascript can call. You may be able to create a snippet of Javascript loaded by a javascript:
URL that obtains your DOM, or walks your list of links, or something, sending the results back to you via the callback object you registered via addJavascriptInterface()
.
这篇关于有没有办法在 Android 应用程序的 webview 中获取 HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!