从Android WebView获取iframe数据 [英] Getting iframe data from Android WebView
问题描述
我有一个包含iframe的网页:
I have a web page that contain an 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:
for getting all of html source, i used this javascript:
javascript:HTMLOUT.processHTML(document.documentElement.outerHTML);
但是,当调用侦听器时,我只会看到:
But, when the listener is invoked, i just see:
<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文档都丢失了.我怎么能把它们全部拿走?
the issue is that all iframe document is missed. How can i get them all?
我还尝试使用JSOUP获取页面.在这种情况下,我只会得到:
I also tried to get the page using JSOUP. in that case, i'm only get:
<div id="confIMG" style="display:block;"></div>
PS:我尝试使用Chrome浏览器进行检查.我只有在 elements
标签中使用开发人员选项/开发人员工具
时才能看到源代码.
PS: i tried to check using Chrome browser. I can only see source code when i use developer options / developers tools
into tab elements
.
推荐答案
JSoup不会自动获取iframe内容.
JSoup won't fetch automatically the iframe content if you don't ask it to do so.
首次加载页面后,找到iframe,然后使用Jsoup提取它.
When you have first loaded the page, find the iframe then fetch it with Jsoup.
Document doc=...
Element ifrmy = doc.select("#ifrmy").first();
if (ifrmy!=null) {
Document iframeContent = Jsoup.connect(ifrmy.attr("src")).get();
// ...
}
这篇关于从Android WebView获取iframe数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!