【问题标题】:Getting iframe data from Android WebView从 Android WebView 获取 iframe 数据
【发布时间】:2015-12-08 16:58:51
【问题描述】:

我有一个包含 iframe 的网页:

<div id="confIMG" style="display:block;">
   <iframe id="ifrmy" src="http://www.example.com" style="margin:0;padding:0;border:0;overflow:hidden;height:200px;width:90%;'" scrolling="no">
   </iframe>
   #document
   <!DOCTYPE html>
   <html>
      <head>....</head>
      <body>....</body>
   </html>
</div>

为了获取所有的 html 源代码,我使用了这个 javascript:

javascript:HTMLOUT.processHTML(document.documentElement.outerHTML);

但是,当调用监听器时,我只看到:

<div id="confIMG" style="display:block;">
   <iframe id="ifrmy" src="http://www.example.com" style="margin:0;padding:0;border:0;overflow:hidden;height:200px;width:90%;'" scrolling="no">
   </iframe>
</div>

问题是所有 iframe 文档都丢失了。我怎样才能得到它们?

我还尝试使用 JSOUP 获取页面。在那种情况下,我只能得到:

<div id="confIMG" style="display:block;"></div>

PS:我尝试使用 Chrome 浏览器进行检查。当我使用developer options / developers tools 进入标签elements 时,我只能看到源代码。

【问题讨论】:

    标签: javascript android html webview jsoup


    【解决方案1】:

    如果您不要求,JSoup 不会自动获取 iframe 内容。

    当你第一次加载页面时,找到 iframe 然后用 Jsoup 获取它。

    Document doc=...
    Element ifrmy = doc.select("#ifrmy").first();
    
    if (ifrmy!=null) {
       Document iframeContent = Jsoup.connect(ifrmy.attr("src")).get();
       // ...
    }
    

    【讨论】:

    • 谢谢,但我发现获取 iframe(而不是内容,而只是 TAG)的唯一方法是使用 javascript...当我尝试使用 JSOUP 获取页面时,我得到了空的DIV!似乎 JSOUP 只是获得了第一个 DIV 级别
    猜你喜欢
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 2021-10-14
    相关资源
    最近更新 更多