zoukankan      html  css  js  c++  java
  • RPA中需要注意的问题

    需要杀死进程

    在用代码实现poc的时候,有的时候就需要先杀死进程,不需要关闭,所以要执行下面的代码,有的时候你就是想不起来这个点。
    image.png

    非常喜欢的一段代码

    try:
        import re
    
        log.info("task-event:开始读取一封邮件")
        # 赋值给当前用户
        current_one = get_select_element(page)
    
        # 判断是否消息
        html = current_one.get_attr("outerHTML")
        is_readed = "已读消息" in html
    
    
        title = re.search(r"Col3.*", html).group().split(">")[1].split("<")[0]
        date = re.search(r"Col4.*", html).group().split(">")[1].split("<")[0]
        content = ""
        sender = ""
        user_name = ""
        phone_no = ""
        attach_count = 0
        dir_name = re.sub("[?:<>|/"*]", "_", title + date).replace("\", "_")
    
        # 如果时间不满足要求
        if not is_need_deal_date(date):
            break
    
        is_need = False
    
        # 邮件未读 则进行读取 并获取正文
        if not is_readed:
            open_current(page)
            # 读取正文 并下载附件 获取输入邮箱
            content = get_content(page)
            sender = get_sender(page)
            # 判断是否是正常注销逻辑
            is_need, user_name, phone_no = check_is_need(title, content)
    
            if is_need:
                # 下载附件
                log.info("task-event:下载附件")
                if not os.path.exists(download_path):
                    os.make_dirs(download_path)
                attach_count = download_attach(page, download_path, get_zhuxiao_attach_dir(dir_name))
                log.info("attach_count %d", attach_count)
            close_tab(page)
            if debug:
                mark_current(page, False)
            else:
                mark_current(page, is_need)
    
            if is_need and not phone_no:
                # 回复邮件 没有联系号码
                replay(page)
                wait_new_tabs_succ(page, 60)
    
                # 切换到正文
                page.add_element("frame", xpath="//iframe[contains(@id, 'bodyrich-editorframe')]")
                page.web_driver.switch_to.frame(page.get_element("frame").element)
                xpath = '''//body'''
                page.add_element("edit_body", xpath=xpath)
                edit_body = page.get_element("edit_body")
                edit_body.focus()
                edit_body = edit_body.element
                import rpa.win32
    
                rpa.win32.copy_str_set(REPLAY_TEMPLETE1)
                from rpa import Keys
    
                edit_body.send_keys(Keys.CONTROL, 'a')
                edit_body.send_keys(Keys.CONTROL, 'v')
    
                send(page)
                wait_send_succ(page, 60)
                append_line(excel, u"格式错误",
                            ["否", "手机号提取失败", user_name, phone_no, sender, title, date, content, attach_count, dir_name])
            elif is_need:
                # 写入excel
                append_line(excel, u"注销",
                            ["", "", user_name, phone_no, sender, title, date, content, attach_count, dir_name])
                pass
    
        log.info("title:%s date:%s, content:%d, sender:%s, user_name:%s, phone_no:%s", title, date, len(content), ,
                 user_name, phone_no)
        excel.save()
        select_next(page)
        last_one = current_one.element
        current_one = get_select_element(page).element
    except:
        import traceback
    
        log.error(traceback.format_exc())
    

    看mentor代码的心得

    1、mentor代码写的很清晰,封装思想很强
    2、事情要考虑全面,流程也要考虑全面,增加代码的健壮性,后期可以做更多的修改,可以根据客户提出的不同问题实现相应的代码
    3、做事要认真仔细,要检查,要检查好几遍,不能似是而非,这样的态度是不可取的
    4、要学习mentor的代码是怎么样写的,怎样写清晰,怎样写容易让人懂,怎样用更简洁易懂的代码去实现更多的需求,不要无用代码
    
  • 相关阅读:
    Windows 7 NVMe补丁(包括官网下载链接)
    最近做的项目的数据处理及可视化小结
    debugging tools for windows 10下载安装问题
    QT安装过程中出现的问题
    Datasnap 中序列化和反序列化
    C# POST multipart/form-data 方式提交数据
    Delphi的前景
    Delphi 禁止重复运行同一程序的方法
    Delphi7 打开工程报错 '找不到指定的模块'&'EOIesysError'
    Delphi7 “cannot Create output File ..inproject1.exe”
  • 原文地址:https://www.cnblogs.com/yanjiayi098-001/p/12365859.html
Copyright © 2011-2022 走看看