红星闪闪的M 2021-04-01 16:36 采纳率: 57.1%
浏览 36
已采纳

能帮忙看看为什么执行不下去了吗 ?

import os
import xlwings as xw
from selenium import webdriver
from WechatPCAPI import WechatPCAPI
import time
from time import sleep

def on_messages(message):
    global wx_inst
    try:
        if message['data']['from_wxid'] not in ['floatbottle','medianote'] :
            if message['data']['msg'] in ['发数据'] and message['data']['send_or_recv'][0] == '0':
                wx_inst.send_text(to_user=message['data']['from_wxid'], msg='收到,很高兴为您服务,执行完毕需要6分钟')
                profile = webdriver.FirefoxProfile ()
                profile.set_preference ('browser.download.dir', 'E:\\下载')
                profile.set_preference ('browser.download.folderList', 2)
                profile.set_preference ('browser.download.manager.showWhenStarting', False)
                profile.set_preference ('browser.helperApps.neverAsk.saveToDisk', 'application/x-excel')
                driver = webdriver.Firefox (firefox_profile=profile)
                driver.get ('http://report2.hualife.cc:8071/WebReport/ReportServer?op=fs')
                driver.maximize_window ()
                time.sleep (3)
                driver.find_element_by_xpath ("/html/body/div[2]/div[3]/div[2]/input").send_keys ("*****")
                driver.find_element_by_xpath ("/html/body/div[2]/div[3]/div[3]/input").send_keys ("******")
                driver.find_element_by_id ("fs-login-btn").click ()
                time.sleep (3)
                driver.find_element_by_xpath ("/html/body/div[1]/div[1]/div[1]/div[1]/div/ul/li[1]/a/span[2]").click ()
                driver.find_element_by_xpath ("/html/body/div[1]/div[1]/div[1]/div[1]/div/ul/li[1]/ul/li[1]/a/span").click ()
                driver.find_element_by_xpath ("/html/body/div[1]/div[1]/div[1]/div[1]/div/ul/li/ul/li[1]/ul/li[1]/a/span").click ()
                time.sleep (2)
                driver.switch_to.frame (driver.find_element_by_xpath ("/html/body/div[1]/div[2]/div/div[4]/iframe[2]"))
                time.sleep (4)
                driver.find_element_by_xpath ("/html/body/div[1]/div[1]/div[2]/div/div[12]/div[2]/div").click ()
                driver.find_element_by_xpath ("/html/body/div[3]/div[3]/div[2]").click ()
                driver.find_element_by_xpath ("/html/body/div[1]/div[1]/div[2]/div/div[19]/div[2]/div").click ()
                driver.find_element_by_xpath ("/html/body/div[1]/div[1]/div[2]/div/div[19]/div[2]/div").click ()
                driver.find_element_by_xpath ("/html/body/div[3]/div[5]/table[1]/tbody/tr[1]/td[6]").click ()
                driver.find_element_by_xpath ("/html/body/div[1]/div[1]/div[2]/div/div[16]/div/div/em/button").click ()
                time.sleep (7)
                driver.find_element_by_xpath ("/html/body/div[2]/table/tbody/tr/td[11]/div/div/div/em/button").click ()
                time.sleep (20)
                app = xw.App (visible=True, add_book=False)#到这里就执行不下去了,也不显示怎么回事
                wb = app.books.open (r'E:/䐁蕳/营销渠道保单清单.xlsx')
                time.sleep (2)
                sht = wb.sheets['sheet1']
                sht.api.Rows (2).Delete ()
                sht.api.Rows (1).Delete ()
                sht.api.Columns (1).Delete ()
                time.sleep (2)
                exist_list = ["正常有效", "标体通过", "承保", "人工核保", "新增险种", "自核通过"]
                rows = sht.api.UsedRange.Rows.count
                cols = sht.api.UsedRange.columns.count
                rng = sht[0, :cols]

                for cell in rng:
                    if cell.value == '保单状态':
                       print (cell.address)
                       a = cell.address
                       a_range = sht.range ("AO2:AO" + str (rows))

                       cell_list = []
                for cell in a_range:
                         cell_list.append (cell)
                cell_list.reverse ()

                print ("   开始调整行和列……")
                for cell in cell_list:
                   if cell.value is not None:
                       find_flag = 0
                for exist_value in exist_list:
                  if cell.value.find (exist_value) != -1:
                       find_flag = 1
                       break
                  else:
                       continue
                if find_flag == 0:
                     cell_to_del = cell.address
                     sht.range (cell_to_del).api.EntireRow.Delete ()
                     time.sleep (2)
                     driver.close ()
                     wb1 = app.books.open (r"C:/Users/Administrator/Desktop/KPI2.xlsm")
                     time.sleep (8)
                     sht1 = wb1.sheets['更新业绩表']
                     sht1.range ("a1").expand ("table").clear_contents ()
                     wb.sheets["sheet1"].range ("a1").expand ("table").api.Copy (sht1.range ('a1').api)
                     wb.close ()
                     os.remove (r'E:/䐁蕳/营销渠道保单清单.xlsx')
                     app.calculate ()
                     time.sleep (10)
                     wb1.api.Application.Run ("all")
    except:
        print('数据条件不满足')


wx_inst = WechatPCAPI(on_message=on_messages)

 # 启动微信
wx_inst.start_wechat(block=True)
# 等待登陆成功,此时需要人为扫码登录微信
while not wx_inst.get_myself():
    time.sleep(5)
  • 写回答

1条回答 默认 最新

  • 沐川 2021-04-02 12:40
    关注

    哪里执行不下去?把问题描述一下

    ——

    电脑重启一下试试,可能是excel程序的问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码