Obtain personal borrowing information --- library client, borrowing ---

Source: Internet
Author: User

Obtain personal borrowing information --- library client, borrowing ---

In the previous article, I used jsoup to parse my personal information-the Library client. After obtaining basic personal information, I had to: obtain detailed information about the current borrowing.

The method is the same. Use jsoup to parse the borrow information page, obtain the required data, encapsulate it into LendBookInfo, and add it to a List.

The details page of the borrow information is as follows:

Simulate a get request to obtain its html string, and the code is relatively simple

/*** Get the current borrowing information. You must ** @ return */public static String getCurLendInfo () {String curLendInfo = null after login () is called;/*** location -----------/patroninfo ~ S3 * chx/1*82/top * Target -----------/patroninfo ~ S3 * chx/1 ***** 82/items ** tem_location ----/patroninfo ~ S3 * chx/1 ***** 82 ****/HttpGet httpget = null; String tem_location = location. substring (0, location. lastIndexOf ("/"); System. out. println ("tem_location ---->" + tem_location); try {httpget = new HttpGet (baseUrl + tem_location + "/items"); response = httpclient.exe cute (httpget ); // send the get request int code = response. getStatusLine (). getStatusCode (); System. out. println (response. getStatusLine (); if (code = 200) {if (r Esponse! = Null) {curLendInfo = EntityUtils. toString (response. getEntity (), HTTP. UTF_8) ;}} catch (ClientProtocolException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} return curLendInfo ;}


After obtaining html, you can use jsoup for parsing. Open firedebug for analysis. The Code is as follows:

/*** Obtain the number of borrowed items ** @ param lendInfoHtml * Details html * @ return */public static List <LendBookInfo> getLendBookInfos (String lendInfoHtml) {List <LendBookInfo> lendBookInfos = new ArrayList <> (); Document document = Jsoup. parse (lendInfoHtml); Element table = document. getElementsByClass ("patFunc "). get (0); // table Elements items = table. getElementsByClass ("patFuncEntry"); // a set of number information for (Element item: items) {LendBookInfo bookInfo = null; Element ele_title = item. getElementsByClass ("patFuncTitle "). get (0); // Title String bookDetail = ele_title.child (0 ). text (); Element ele_barCode = item. getElementsByClass ("patFuncBarcode "). get (0); // barCode String barCode = ele_barCode.text (); Element ele_status = item. getElementsByClass ("patFuncStatus "). get (0); // status String status = ele_status.text (); Element ele_callNumber = item. getElementsByClass ("patFuncCallNo "). get (0); // String callNumber = ele_callNumber.text (); bookInfo = new LendBookInfo (bookDetail, callNumber, status, barCode); lendBookInfos. add (bookInfo);} return lendBookInfos ;}

The test is as follows:


Public static void main (String [] args) {boolean isConn = LibraryUtil. login (stuNo, password);/*** Save the information to the database if the login is successful (the student ID and password must 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 (); String lendInfoHtml = LibraryUtil. getCurLendInfo (); List <LendBookInfo> lendBookInfos = UserInfoHandler. getLendBookInfos (lendInfoHtml); for (LendBookInfo bookInfo: lendBookInfos) {System. out. println (bookInfo );}}}

Test results:



To be continued ......

Related Article

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.