2015-04-01 108 views

回答

0

使用Element.parent(),它將獲得該元素的父項。

String html = "<div> Blah <p> However </p> </div>"; 
Document doc = Jsoup.parseBodyFragment(html); 
Element p = doc.select("p").first(); 

String myText = p.parent().text(); //selects the enclosing div, and gets all the text in the div. 

System.out.println(myText); 

打印:

Blah However 

AFAIK,對父母沒有選擇,所以你可能必須去與日parent()方法。