平安银行信用卡电子账单读取

原创
2016/06/04 16:39
阅读数 539
public class PingAnBankBill  {
    // public static BillModal readBill(Document document) {
   public static List<TempBillModal> readBill(String mailContent) {
       List<TempBillModal> billModalList = new ArrayList<TempBillModal>();
        TempBillModal billModal = new TempBillModal();
        Document document = Jsoup.parse(mailContent);
        billModal.setBankname("平安银行");
        //解析获得持卡人
        String cardUserStr = document.select("strong:containsOwn(尊敬的)").text();
        String cardUser = cardUserStr.replace("尊敬的", "").replace(" :", "").trim();
        billModal.setCarduser(cardUser);
        System.out.println("户主:" + cardUser);
        //解析获得账单月份
        String monthStr = document.select("td:containsOwn(月的信用卡对账单)").first().child(0).html();
       // monthStr = monthStr.substring(1,monthStr.length()-1);
        monthStr = monthStr.replaceAll("&nbsp;","");
        System.out.println(monthStr);
        if(monthStr.trim().indexOf("0")==0){
            monthStr = monthStr.substring(1,monthStr.length());
        }
        int month = Integer.parseInt(monthStr);
         billModal.setBillmonth(month);
        System.out.println("账单月"+ month);
        //解析获得本期账单日
        String billDateStr = document.select("td:containsOwn(本期账单日)").first().nextElementSibling().text();
        billModal.setBilldate(billDateStr);
        System.out.println("本期账单日:"+billDateStr);
        //解析本期还款日
        String repayDateStr = document.select("strong:containsOwn(本期还款日)").parents().first().nextElementSibling().text();
        billModal.setRepaydate(repayDateStr);
        System.out.println("本期还款日:"+repayDateStr);
        //解析信用额度
        String creditlimitStr = document.select("td:containsOwn(信用额度)").first().nextElementSibling().text();
        creditlimitStr = creditlimitStr.replaceAll("¥ ", "").replace(",","");
        BigDecimal creditlimit = new BigDecimal(creditlimitStr);
        billModal.setCreditlimit(creditlimit);
        System.out.println("信用额度为¥:"+creditlimit.toString());
        //解析取现额度
        String crashlimitStr = document.select("td:containsOwn(取现额度)").first().nextElementSibling().text();
        crashlimitStr = crashlimitStr.replaceAll("¥ ", "").replace(",","");
        BigDecimal crashlimit = new BigDecimal(crashlimitStr);
        billModal.setCrashlimit(crashlimit);
        System.out.println("取额限度为¥:"+creditlimit.toString());
        //解析本期还款
        String needpayStr = document.select("strong:containsOwn(本期应还金额)").parents()
                .get(4)
                .nextElementSibling()
                .child(0)
                .child(0)
                .child(0)
                .child(0)
                .child(0).text();
        needpayStr = needpayStr.replaceAll("¥ ", "").replace(",","");
        BigDecimal needpay = new BigDecimal(needpayStr);
        billModal.setNeddrepay(needpay);
        System.out.println("本期还款为¥"+needpay.toString());
        //解析最低还款
        String lowpayStr = document.select("strong:containsOwn(本期应还金额)").parents()
                .get(4)
                .nextElementSibling()
                .child(0)//table
                .child(0)//tbody
                .child(2)//tr
                .child(0)//td
                .text();
        lowpayStr = lowpayStr.replaceAll("¥ ", "").replace(",","");
        BigDecimal lowpay = new BigDecimal(lowpayStr);
        billModal.setLowrepay(lowpay);
        System.out.println("最低还款为¥"+lowpay);
        //解析交易明细
        Elements tradeElements = document.select("td:containsOwn(人民币账户交易明细)").first().parents()
                .get(4)
                .nextElementSibling()
                .child(0)
                .child(0)//table
                .child(0)//tbody
                .children().select("tr[height=38]");
        List<BillDetail> billDetailList = new ArrayList<BillDetail>();
        for(int i=0; i <tradeElements.size();i++){
            BillDetail billDetail = new BillDetail();
            //从第二个开始第一个为表头
            Element element = tradeElements.get(i);
            int size  = element.children().size();
            String tradedate = element.child(size-4).text();
            billDetail.setTradedate(tradedate);
            System.out.println("交易日期"+tradedate);
            String detail = element.child(size-2).text();
            billDetail.setDetail(detail);
            System.out.println("交易明细:"+detail);
            String trademoneyStr = element.child(size-1).text();
            trademoneyStr = trademoneyStr.replaceAll("¥ ", "").replaceAll(",","");
            trademoneyStr = trademoneyStr.substring(0,trademoneyStr.length()-1);
            BigDecimal trademoney = new BigDecimal(trademoneyStr);
            billDetail.setMoney(trademoney);
            System.out.println("交易金额" + trademoney.toString());
            billDetailList.add(billDetail);
        }
       billModal.setBillDetailList(billDetailList);
       billModalList.add(billModal);
        return billModalList;
    }

    /*public static void main(String[] args) {

        try {
            Document document = Jsoup.connect("http://127.0.0.1/card/pingan081.html").get();
            PingAnBankBill.readBill(document);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }*/
}

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部