在上一篇利用jsoup解析个人信息----图书馆client,获得个人基本信息后。便有了进一步的需求:获取当前借阅的具体信息

获取的方法还是一样的。利用jsoup解析借阅信息页面,获得所需数据,封装成LendBookInfo,然后将其增加一个List中。

借阅信息详情页例如以下:

模拟get请求得到其html字符串。代码较简单

/**
*获取当前借阅信息。 必须在login()调用之后
*
* @return
*/
public static String getCurLendInfo() {
String curLendInfo = null; /**
*
* location----------- /patroninfo~S3*chx/1****82/top
*
* 目标-------------/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);// 发送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。进行分析。

代码例如以下:

	/**
* 获取借阅的数目信息
*
* @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");// 数目信息集合
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);// 状态
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; }

測试例如以下:

public static void main(String[] args) {

		boolean isConn = LibraryUtil.login(stuNo, password);

		/**
* 若登陆成功则将信息保存到数据库(学号、密码须要加密)。 */
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);
}
}
}

測试结果:

待续……

获取个人借阅信息---图书馆client的更多相关文章

  1. Python爬虫实战---抓取图书馆借阅信息

    Python爬虫实战---抓取图书馆借阅信息 原创作品,引用请表明出处:Python爬虫实战---抓取图书馆借阅信息 前段时间在图书馆借了很多书,借得多了就容易忘记每本书的应还日期,老是担心自己会违约 ...

  2. Asp.NET MVC 使用 SignalR 实现推送功能二(Hubs 在线聊天室 获取保存用户信息)

    简单介绍 关于SignalR的简单实用 请参考 Asp.NET MVC 使用 SignalR 实现推送功能一(Hubs 在线聊天室) 在上一篇中,我们只是介绍了简单的消息推送,今天我们来修改一下,实现 ...

  3. # Linux Whois3获取 运营商信息

    Linux Whois3获取 运营商信息 APNIC是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的,并提供了一个查询工具,下面就让我们看看如何在Linux ...

  4. 测试框架httpclent 3.获取cookie的信息,然后带cookies去发送请求

    在properties文件里面: startupWithCookies.json [ { "description":"这是一个会返回cookies信息的get请求&qu ...

  5. 反射01 Class类的使用、动态加载类、类类型说明、获取类的信息

    0 Java反射机制 反射(Reflection)是 Java 的高级特性之一,是框架实现的基础. 0.1 定义 Java 反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对 ...

  6. 小白学react之网页获取微信用户信息

    通过上一篇<小白学react之EJS模版实战>我们学习了怎样通过EJS模版生成我们高定制化的index.html文件. 本篇我们将会继续延续我们的alt-tutorial项目的实战计划.去 ...

  7. php获取YouTube视频信息的方法

    YouTube的视频地址格式https://www.youtube.com/watch?v=[VIDEO_ID]例子:https://www.youtube.com/watch?v=psvkyf3Pz ...

  8. sql 2012中获取表的信息,包含字段的描述

    1.获取数据库中的表 select name from sysobjects where type='U' 2.获取表字段(此处是Route表) Select name from syscolumns ...

  9. ThinPHP命名空间,连接数据库是要修改的配置文件,Model数据模型层,跨控制器调用,如何获取系统常量信息,

    一.命名空间(主要是为了实现自动加载类) *命名空间(相当于虚拟的目录),为了让类有一个统一的文件夹来管理(可以自动加载'类'),每个文件都要有命名空间*tp如何做命名空间:*TP框架下有一个初始命名 ...

随机推荐

  1. 英语影视台词---五、And Then There Were None

    英语影视台词---五.And Then There Were None 一.总结 一句话总结:求阿加莎·克里斯蒂小说<无人生还>的英文版<And Then There Were No ...

  2. pandas入门10分钟——serries其实就是data frame的一列数据

    10 Minutes to pandas This is a short introduction to pandas, geared mainly for new users. You can se ...

  3. 44.AngularJS Bootstrap

    转自:https://www.cnblogs.com/best/tag/Angular/ Bootstrap 你可以在你的 AngularJS 应用中加入 Twitter Bootstrap,你可以在 ...

  4. Struts2国际化-getText()方法

    转自https://blog.csdn.net/qq_43560838/article/details/83747604 一:简单理解 国际化简称i18n,其来源是英文单词 international ...

  5. HTML 表格 做个人简历

    根据老师上课讲的常用标签与表格的应用 终于做出了第一个网页版的个人简历 虽然作出来了 但是感觉其中方法有点儿问题 还需要进一步的改进中…… <!DOCTYPE html PUBLIC " ...

  6. Gson解析List的一点小问题

    这阵子在使用gson解析时遇到了点小麻烦,因为一直用的fastjson,最近一个项目里使用的gson,需要解析list集合,查资料都是使用TypeToken解决,相对比较麻烦,下面为大伙推荐一种简便的 ...

  7. JS动态创建表单post提交

    <script> //@创建表单方法 function post(URL, PARAMS) { var temp = document.createElement("form&q ...

  8. 运行npm start vue.js项目 出现 npm ERR! missing script: start 错误

    npm ERR! missing script: start 错误 有可能缺少依赖包,运行nmp install安装依赖(一般都依赖很多包,过程有点慢),安装完后发现多一个 node_modules文 ...

  9. Redis-Sentinel原理及配置详解【转】

    https://www.cnblogs.com/zhoujinyi/p/5570024.html

  10. js cookie 页面倒计时

    疯了啦 写了一篇没有保存需求:页面倒计时 只从第一次加购开始公共方法cookie的设置 获取function getCookie(c_name){ if (document.cookie.length ...