Turn https://blog.csdn.net/N_007/article/details/78835526
Reference CNBankCard major Bank of China card number inquiry
First, get the name of the interface Alipay
Access to bank information in accordance with the interface card
https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=银行卡卡号&cardBinCheck=true
Return result value (josn type)
{"bank":"CCB","validated":true,"cardType":"DC","key":"银行卡卡号","messages":[],"stat":"ok"}
Where the bank is the bank code
Second, the bank code -> name of the bank
reptile crawling Alipay bank partner page information.
See page structure, as shown in FIG.
We need to get the key fields is
<span title="" class="icon "></span>
Then get the name of the bank
Third, banks LOGO
https://apimg.alipay.com/combo.png?d=cashier&t=银行代码
If you need more pictures, direct, "" separated by commas, for example,
https://apimg.alipay.com/combo.png?d=cashier&t=ABC,CCB
四、java 代码实现
1.pom.xml
使用 hutool 工具包来发起 http 请求,以及后续爬虫功能
参考文档:Hutool
<dependency>
<groupId>com.xiaoleilu</groupId>
<artifactId>hutool-all</artifactId>
<version>3.2.3</version>
</dependency>
2.mian method
public static void main(String[] args) throws Exception{
String bankNo = "银行卡号";
//银行代码请求接口 url
String url = "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo="+bankNo+"&cardBinCheck=true";
//发送请求,得到 josn 类型的字符串
String result = HttpUtil.get(url);
// 转为 Json 对象
JSONObject json = new JSONObject(result);
//获取到 bank 代码
String bank = String.valueOf(json.get("bank"));
//爬取支付宝银行合作商页面
String listContent = HttpUtil.get("http://ab.alipay.com/i/yinhang.htm","gb2312");
//过滤得到需要的银行名称
List<String> titles = ReUtil.findAll("<span title=\"(.*?)\" class=\"icon "+bank+"\">(.*?)</span>", listContent, 2);
for (String title : titles) {
//打印银行名称
Console.log(title);
}
}