从Android WebView获取iframe数据

Getting iframe data from Android WebView

本文关键字:iframe 数据 获取 WebView Android      更新时间:2023-09-26

我有一个网页,其中包含一个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>

附言:我试着用Chrome浏览器查看。当我在选项卡elements中使用developer options / developers tools时,我只能看到源代码。

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

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

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