Extracting attributes from text and HTML elements

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

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.

Guess you like

Origin www.cnblogs.com/deityjian/p/12541625.html