- String html = "<p>An <a href='http://www.oschina.net/'><b>example</b></a> link.</p>";
- Document doc = Jsoup.parse(html);
- Element link = doc.select("a").first();
- String text = doc.body().text(); // "An example link"
- String linkHref = link.attr("href"); // "http://www.oschina.net/"
- String linkText = link.text(); // "example""
- String linkOuterH = link.outerHtml();
- // "<a href="examplehttp://www.oschina.net/"><b>example</b></a>"
- String linkInnerH = link.html(); // "<b>example</b>"
复制代码
sunwy注:代码虽然简单,但很有学习意义。
|