美文网首页
财务机器人——网银自动下载

财务机器人——网银自动下载

作者: hhmy123 | 来源:发表于2019-04-29 09:28 被阅读0次

    内容会同步分享到公众号:CPA君

    中国银行网银自动下载,直接上代码

    # 代码开始
    from selenium import webdriver

    import time

    import datetime

    import os

    import win32com.client

    driver = webdriver.Chrome()

    driver.get("https://co.ebsnew.boc.cn/boccp/login_CA.html?entryType=5")

    time.sleep(2)

    # 这里可能会要求输入Ukey,每家的情况不一样,中行的我会放一个另一个代码,需要的时候一起执行即可

    def everyday():

    driver.find_element_by_xpath('//*[@id="SecEditCtrl1"]').send_keys('******')# 密码(可更改)

        time.sleep(1)

    driver.find_element_by_xpath('//*[@id="btn_login_62112"]/span').click()# 登陆按钮

        time.sleep(3)

    driver.find_element_by_xpath('//*[@id="nav307"]/ul/li[2]/a/span').click()# 账户管理

        time.sleep(1)

    driver.find_element_by_xpath('//*[@id="leftMenu"]/div[1]/dl[1]/dd[2]/a').click()# 今日交易

        time.sleep(2)

    try:

    driver.find_element_by_xpath('//*[@id="leftMenuRollup"]').click()# 收起侧边栏

        except:

    pass

        time.sleep(2)

    driver.find_element_by_xpath('//*[@id="today_main_contiditon_chk_all"]').click()# 账户全选

        js ="window.scrollTo(0,document.body.scrollHeight)"  # 下拉到底

        driver.execute_script(js)

    time.sleep(2)

    # driver.find_element(By.ID, 'btn_shenchengjiaoyixiazaiwenjan_62435').click()  # 生成(备用)

        driver.find_element_by_css_selector('#btn_shenchengjiaoyixiazaiwenjan_58385 > span').click()# 生成

        time.sleep(2)

    down_file_nm = driver.find_element_by_xpath(

    '//*[@id="today_deal_download_pop"]/div/div/div/div/p[3]/span[2]').text# 提取文件名

        time.sleep(2)

    driver.find_element_by_xpath('//*[@id="today_deal_download_pop"]/div/div/div/p/a/span').click()# 返回

        time.sleep(15)

    driver.find_element_by_xpath('//*[@id="today_main_tab_download"]/span').click()# 交易下载

        time.sleep(2)

    driver.find_element_by_css_selector(

    '#today_main_tab_download_div > div > div > table > tbody > tr > td.last > a').click()# 下载按钮

        # date_tradebegindate_62180river.find_element_by_link_text("下载").click()    # 下载按钮备用

        time.sleep(5)

    file_path =r'C:\Users\Administrator\Downloads\%s.xls' % down_file_nm# 发送邮件

        today_date = datetime.date.today()

    outlook = win32com.client.Dispatch('Outlook.Application')

    mail_item = outlook.CreateItem(0)# 0: olMailItem

        receiver ='*********' # 填写收件人

        mail_item.To = receiver

    mail_item.Subject ='2019网银' +str(today_date)

    mail_item.BodyFormat =2  # 2: Html format

        mail_item.HTMLBody ='''

        <H2>今日网银、烦请查收,谢谢!'''

        print(file_path)

    mail_item.Attachments.Add(file_path)

    mail_item.Send()

    time.sleep(100)

    os.remove(file_path)# 删除文件

    def send_error():

    outlook = win32com.client.Dispatch('Outlook.Application')

    mail_item = outlook.CreateItem(0)# 0: olMailItem

        mail_item.Recipients.Add('*****')# 填写邮箱

        mail_item.Subject ='网银发送失败提醒'

        mail_item.BodyFormat =2  # 2: Html format

        mail_item.HTMLBody ='''网银发送失败'''

        mail_item.Send()

    def main():

    try:

    everyday()

    except:

    send_error()

    if __name__ =='__main__':

    main()

    driver.close()

    # 代码结束

      第一篇简书,就谈一点感悟吧,当高中时听说找工作时被要求做PPT,当本科毕业论文被word格式虐了好几版,当研究生做数据觉得spss难用时,笔者都没有意识到office的重要性。从第一天工作接触到vlookup,才真正打开了我对于office特别是excel的大门,也是通过excel在工作中实现了价值,从函数、透视表、图表到宏、RPA、python,最终实现财务流程的自动化。

        本科的时候,看到有些人要考计算机二级,当时笔者已经从英语跨考到会计,觉得以后这两个吃饭的手艺应该都不会接触到编程,事实证明笔者错了,摩根大通已要求所有资管部门员工必须学习编程,而当前的财务机器人的快速发展,已经让传统会计岌岌可危。笔者在工作中通过VBA和python也体会到编程的强大,也大胆预言编程在未来可能会像office一样,成为我们一种必备的技能。

    欢迎大家关注我的公众号:CPA君

    里面会分享有关于财务的一切,CPA、excel、RPA(财务机器人、uipath、python)

    相关文章

      网友评论

          本文标题:财务机器人——网银自动下载

          本文链接:https://www.haomeiwen.com/subject/neeenqtx.html