This function is mainly used: first determine the post address, then obtain the HTML code, parse the HTML through jsoup, and then extract the building owner to save it to book.html.
In addition to the use of jsoup, we should look at the general structure of the post:
1. Analyze the User Name of the landlord first:
If you look at the HTML code, you can know that the user name is in the DIV of class = "p_author_name". The landlord is of course the first, so:
String LZ = Doc. getelementsbyclass ("p_author_name" (.get(0).html ();
2. The body of the reply is found in the DIV class = "p_postlist". First, extract this element E = Doc. getelementsbyclass ("p_postlist"). Get (0 );
3. retrieve each reply class = "l_post" and traverse
Elements es = E. getelementsbyclass ("l_post"); // retrieves each record for (element TMP: ES) {// traverses if (LZ. equals (TMP. getelementsbyclass ("p_author_name" ).html () {// save it as string html = TMP. getelementsbyclass ("d_content" (.get(0).html (); html = html. replaceall ("
4. Determine whether the post has reached the end page
Each post contains two pages. Take out any one of them and judge whether it contains the "next page". If it is gone, it is the last page.
5. Save it.
Because we only extract the content in the DIV, it is a bit messy to save. You can write a CSS file and then save it.
Complete code:
Private void see (string URL) {try {int page = 0; stringbuffer sb = new stringbuffer (); document DOC = jsoup. connect (URL ). get (); string LZ = Doc. getelementsbyclass ("p_author_name" (.get(0).html (); // obtain the username of the first user, that is, the main user elements posts = NULL; do {Element E = Doc. getelementsbyclass ("p_postlist "). get (0); // get the divelements es = E. getelementsbyclass ("l_post"); // retrieves each record for (element TMP: ES) {// traverses if (LZ. equals (TMP. getelementsbyclass ("p_author_name" ).html () {string html = TMP. getelementsbyclass ("d_content" (.get(0).html (); html = html. replaceall ("