On a httpclient simulation landing in the Jiaotong University library to solve the landing, after landing can view personal information. Fewer personal information items,
The main is: name, telephone, the current borrowing, arrears amount.
To view its HTML code:
The following begins the parsing:
Code
Package Com.ali.login.spider;import Org.jsoup.jsoup;import Org.jsoup.nodes.document;import Org.jsoup.select.elements;import com.ali.login.bean.userinfo;/** * Business class for handling user information * * @author words * */public class Userinfoha ndler {/** * Resolves user information based on returned HTML * * @return */public static UserInfo GetUserInfo (String htmlstr) {Document document = Jsou P.parse (HTMLSTR); Elements patnameaddress = Document.getelementsbyclass ("patnameaddress"); Elements BRS = patnameaddress.select ("br");//For (Element Br:brs) {////System.out.println (br.nextsibling (). ToString ( ). Trim ());//}string Phonenum = Brs.get (0). nextSibling (). toString (); String curlend = brs.get (1). nextSibling (). toString (); int curlendnum = Integer.parseint (curlend.substring ( Curlend.indexof (":") + 1); System.out.println (Curlendnum); String debt = Brs.get (4). NextSibling (). toString ();d EBT = debt.substring (Debt.indexof (":") + 1); Elements infos = patnameaddress.get (0). Children (); String name = Infos.get (0). text (); UserInfo UserInfo = new UserInfo (name, PhonenuM, Curlendnum, debt); return userInfo;}}
When logging in, the user's details (plus user name and password) are encapsulated into a UserInfo object, which is then stored in the database.
Test code:
Boolean isconn = Libraryutil.login (Stuno, password);/** * If the login is successful, save the information to the database (number, password needs to be encrypted). */if (isconn) {String resulthtml = libraryutil.getresulthtml (); UserInfo UserInfo = Userinfohandler.getuserinfo (resulthtml); Userinfo.setstuno (Stuno); Userinfo.setpassword ( password); System.out.println ("========"); System.out.println (Userinfo.tostring ());}
So we get the user's information.
Reference: Jsoup: Parsing HTML Usage Summary
Using Jsoup to parse personal information----Library client