天天看點

平安銀行信用卡電子賬單讀取

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();
        }
    }*/
}
           

轉載于:https://my.oschina.net/riaway/blog/687130