Problem
After parsing a document, and finding some elements, you'll want to get at the data inside those elements.
Solution
For example:
- String html = "An example link.
"; - 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://example.com/"
- String linkText = link.text(); // "example""
- String linkOuterH = link.outerHtml();
- // "example"
- String linkInnerH = link.html(); // "example"
The methods above are the core of the element data access methods. There are additional others:
All of these accessor methods have corresponding setter methods to change the data.
See also
* The reference documentation for Element and the collection Elements class
* Working with URLs
* finding elements with the CSS selector syntax
沒有留言:
張貼留言