problem
After parsing get a Document instance of the object, and found some of the elements you want to get data in these elements.
method
- To get the value of a property, you can use
Node.attr(String key)
the method - For a text element, it is possible to use
Element.text()
methods - To get to the element or attribute in HTML content, you can use
Element.html()
, orNode.outerHtml()
method
Example:
HTML = String "<P> <a href='http://example.com/'> An <B> Example </ B> </a> Link </ P>." ; The Document DOC = Jsoup.parse ( HTML); // parse HTML string returns a Document implement the element Link doc.select = ( "a") first ();. // find the first element of a string text = doc.body () text ().; // "An Example link" // get the text string string linkHref = link.attr ( "href"); // " http://example.com/ " // get the link address string linkText = link.text (); // "Example" "// get a text link address String linkOuterH = link.outerHtml (); // "<A href ="http://example.com"><b>example</b></a>" String linkInnerH = link.html(); // "<b>example</b>"//取得链接内的html内容
Explanation
The above method is a core element of ways to access the data. In addition, other methods may be used:
These accessor methods has a corresponding setter methods to change the data.