目录
一、需求说明
二、页面数据源在内嵌Iframe
三、页面数据源为json
四、页面数据源为js
五、页面数据源为xml
六、代码解析
七、数据库
八、结果展示
一、需求说明
近期有一个项目是爬取多家银行汇率,我提取了几个相似的案例,本文主要讲解页面数据获取方法。
二、页面数据源在内嵌Iframe
中银香港URL为: https://www.bochk.com/tc/investment/rates/deposit.html
实际数据URL为: https://www.bochk.com/whk/rates/depositRates/depositRates-input.action?lang=hk
需要爬取的数据如下图:
页面数据寻找
三、页面数据源为json
汇丰银行URL为: https://www.personal.hsbc.com.hk/1/2/chinese/hk/investments/mkt-info/deposit-rates/interest-rates
实际数据URL为: https://rbwm-api.hsbc.com.hk/digital-pws-tools-investments-eapi-prod-proxy/v1/investments/interest-rate?ccyCode=HKD
需要爬取的数据如下图:
页面数据如下
四、页面数据源为js
建银亚洲URL为: http://www.asia.ccb.com/hongkong_sc/personal/accounts/dep_rates.html
建银亚洲URL为: http://www.ccb.com/cn/home/news/HongKong/hkhqll01.js
需要爬取的数据如下图:
页面数据如下
五、页面数据源为xml
汇丰银行URL为: https://www.dahsing.com/tc/html/program/hong_kong_dollar_deposit_rate.html
汇丰银行URL为: https://www.dahsing.com/tc/html/program/HKRateOutput_chi.xml
需要爬取的数据如下图:
页面数据如下
六、代码解析
代码下载路径如下:
https://download.youkuaiyun.com/download/silentwolfyh/11296203
七、数据库
DROP TABLE IF EXISTS `cmp_mart_rate`;
CREATE TABLE `cmp_mart_rate` (
`bank_code` varchar(11) NOT NULL COMMENT 'bank_code',
`ccy_code` varchar(3) NOT NULL COMMENT 'currency code',
`inrt_code` varchar(12) NOT NULL COMMENT 'interest rate code',
`term_code` varchar(8) NOT NULL COMMENT 'term code',
`band_amount` decimal(21,2) NOT NULL COMMENT 'band amount',
`inrt_rate` decimal(11,6) NOT NULL COMMENT 'interest rate',
`trxn_date` varchar(8) NOT NULL COMMENT 'transaction date',
`sync_time` varchar(23) NOT NULL COMMENT 'synchronize time',
`inrt_status` varchar(1) NOT NULL COMMENT 'inrt status',
`data_create_time` timestamp(3) NOT NULL COMMENT 'data create time',
`data_update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'data update time',
`data_create_user` varchar(32) DEFAULT NULL COMMENT 'data create user',
`data_update_user` varchar(32) DEFAULT NULL COMMENT 'data update user',
`data_version` bigint(19) DEFAULT NULL COMMENT 'data version',
PRIMARY KEY (`inrt_code`,`ccy_code`,`term_code`,`band_amount`,`sync_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;