获取个人借阅信息---图书馆client
在上一篇利用jsoup解析個人信息----圖書館client,獲得個人基本信息后。便有了進一步的需求:獲取當(dāng)前借閱的具體信息
獲取的方法還是一樣的。利用jsoup解析借閱信息頁面,獲得所需數(shù)據(jù),封裝成LendBookInfo,然后將其增加一個List中。
借閱信息詳情頁例如以下:
模擬get請求得到其html字符串。代碼較簡單
/***獲取當(dāng)前借閱信息。 必須在login()調(diào)用之后* * @return*/public static String getCurLendInfo() {String curLendInfo = null;/*** * location----------- /patroninfo~S3*chx/1****82/top* * 目標(biāo)-------------/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.execute(httpget);// 發(fā)送get請求int code = response.getStatusLine().getStatusCode();System.out.println(response.getStatusLine());if (code == 200) {if (response != null) {curLendInfo = EntityUtils.toString(response.getEntity(),HTTP.UTF_8);}}} catch (ClientProtocolException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return curLendInfo;}得到html后。便能夠利用jsoup進行解析。
打開firedebug。進行分析。
代碼例如以下:
/*** 獲取借閱的數(shù)目信息* * @param lendInfoHtml* 借閱信息詳情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);// 表格Elements items = table.getElementsByClass("patFuncEntry");// 數(shù)目信息集合for (Element item : items) {LendBookInfo bookInfo = null;Element ele_title = item.getElementsByClass("patFuncTitle").get(0);// 題名String bookDetail = ele_title.child(0).text();Element ele_barCode = item.getElementsByClass("patFuncBarcode").get(0);// 條形碼String barCode = ele_barCode.text();Element ele_status = item.getElementsByClass("patFuncStatus").get(0);// 狀態(tài)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;}測試?yán)缫韵?#xff1a;
*/ 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); } } }
測試結(jié)果:
待續(xù)……
總結(jié)
以上是生活随笔為你收集整理的获取个人借阅信息---图书馆client的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: a+=b 等价于 a=a+b ?
- 下一篇: [LeetCode]Count of R