1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| ''' 下载招行对账单(按月下载),每月执行一次,下载上个月的对账单。 ''' from selenium import webdriver from selenium.webdriver.edge.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys import time import datetime from loguru import logger
def fileLog(): FileLog= 'cmb.log' logger.add(FileLog,rotation='500MB',encoding='utf-8',enqueue=True)
def getLastMonthStartAndEnd(): today = datetime.date.today() lastMonthEnd = datetime.date(today.year,today.month,1)-datetime.timedelta(1) lastMonthStart = datetime.date(lastMonthEnd.year,lastMonthEnd.month,1) return lastMonthStart,lastMonthEnd
def queryData2(bdate,edate): logger.info('点击对账单打印') driver.find_element(By.XPATH,'//div[text()="对账单打印"]').click() time.sleep(2) driver.find_element(By.XPATH,'/html/body/div[1]/div/div[1]/div[2]/div[2]/div/div[8]/div/div[2]/div[1]/div[2]/div/div/div/div/div/input').click() time.sleep(2) driver.find_element(By.XPATH,'//*[@id="zxc"]/div/div[2]/div/div[1]/div/span[1]/label/span[1]/span').click() time.sleep(5) driver.find_element(By.XPATH,'//span[text()="确定"]').click() time.sleep(2) logger.info('全选所有项目成功') time.sleep(2) logger.info('填写开始日期') begindate = driver.find_element(By.XPATH,'//*[@id="lyContentIn"]/div/div[8]/div/div[2]/div[1]/div[4]/div/div/input[1]') begindate.send_keys(Keys.CONTROL,'a') begindate.send_keys(bdate) time.sleep(2) logger.info('填写结束日期') enddate = driver.find_element(By.XPATH,'//*[@id="lyContentIn"]/div/div[8]/div/div[2]/div[1]/div[4]/div/div/input[2]') enddate.send_keys(Keys.CONTROL,'a') enddate.send_keys(edate) driver.find_element(By.XPATH,'//*[@id="lyContentIn"]/div/div[8]/div/div[1]/span').click() time.sleep(2) driver.find_element(By.XPATH,'//*[@id="lyContentIn"]/div/div[8]/div/div[2]/div[3]/div[2]/div/div/div/div[2]/div[2]/span[2]').click() time.sleep(2) logger.info('删除上次已生成PDF成功') driver.find_element(By.XPATH,'//*[@id="lyContentIn"]/div/div[8]/div/div[2]/div[2]/button').click() time.sleep(300) logger.info('生成PDF成功') driver.find_element(By.XPATH,'//*[@id="lyContentIn"]/div/div[8]/div/div[2]/div[3]/div[2]/div/div/div/div[2]/div[2]/span[1]').click() time.sleep(80) logger.info('下载成功')
def login(): logger.info('打开网页') time.sleep(5) driver.maximize_window() driver.get(r'https://custody.ebank.cmbchina.com/ccsp/Web/index.html#/login/entrance') time.sleep(5) logger.info('UKey登录') driver.find_element(By.XPATH,'//i[text()="UKey登录"]').click() time.sleep(2) driver.find_element(By.XPATH,'//div[@class="pw_ukey"]/div/div').click() time.sleep(1) pwd = driver.find_element(By.XPATH,'//div[@class="pw_ukey"]/div/div') pwd.send_keys('******') driver.find_element(By.XPATH,'//div[@class="bottom_btn ready"]/span').click() time.sleep(20) logger.info('网页登录成功') driver.find_element(By.XPATH,'//span[text()="回单打印"][1]').click() time.sleep(1) logger.info('进入回单打印')
if __name__ == "__main__": fileLog() logger.info('***********招行对账单下载开始*************') s = Service(r'F:\\workspace\\msedgedriver.exe') first,end = getLastMonthStartAndEnd() first = str(first) end = str(end) logger.info('-------开始处理{}招行对账单-------'.format(first+'至'+end)) driver = webdriver.Edge(service=s) login() queryData2(first,end) driver.quit() logger.info('-------{}招行对账单处理完成-------'.format(first+'至'+end))
|