我有这个HTML代码
<div itemprop="doseSchedule">
text1
</div>
<h3><a id="SP3">TITLE</a></h3>
<div>text2</div>
<div itemprop="warning">
text3
</div>
我尝试恢复text2,但仍然无法恢复。我怎么能这样做?
答案 0 :(得分:0)
此代码将执行您想要的操作:
public class JSoupTest {
public static void main(String[] args) throws IOException {
String html = "<div itemprop=\"doseSchedule\">\n"
+ "text1\n"
+ "</div>\n"
+ "<h3><a id=\"SP3\">TITLE</a></h3>\n"
+ "<div>text2</div>\n"
+ "<div itemprop=\"warning\">\n"
+ "text3\n"
+ "</div>";
Document doc = Jsoup.parse(html);
Element e = doc.select("h3").first().nextElementSibling();
System.out.println(e.text());
}
}