2013-04-26 69 views
4

我有這樣的html結構。我想獲得第二個沒有class或id的表。我如何獲得iframe的第二個表格?遍歷iframe使用jsoup

<iframe> 
<html> 
<body> 
    <table><table> 
    <table> 
    <tr><td></td></tr> 
    <tr><td></td></tr> 
    </table> 
</body> 
</html> 
</iframe> 

我想這樣

Elements iframe = doc.select("iframe"); 

for(Element e : iframe) { 
    System.out.println(e.child(0));  
} 

誰能幫助我?

+0

這是你想要解析的真正的'html'嗎?因爲它看起來不正確。 – Darwind 2013-04-26 10:24:58

回答

8

你想遍歷iframe元素嗎?這是更好地從源頭iframe得到 內容類似

Element iframe = doc.select("iframe").first(); 
String iframeSrc = iframe.attr("src"); 

if(iframeSrc != null) { 
    iframeContentDoc = Jsoup.connect(iframeSrc).get(); 
} 

你能做的只有這樣。