Using Jsoup to parse personal information----Library client

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.