簡體   English   中英

從Android WebView獲取iframe數據

[英]Getting iframe data from Android WebView

我有一個包含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 toolselements使用developer options / developers tools時,才能看到源代碼。

如果您不要求JSoup不會自動獲取iframe內容,則JSoup不會自動獲取它。

首次加載頁面后,找到iframe,然后使用Jsoup提取它。

Document doc=...
Element ifrmy = doc.select("#ifrmy").first();

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM