zoukankan      html  css  js  c++  java
  • selenium设置程序失败后重启

    1. 程序出现异常抛出,将异常写入文件,继续执行下一条

        for key, value in I:
            # print(value)
            # 定义临时变量为flase
            flag = False
            browser = None
            try:
                chrome_opt = webdriver.ChromeOptions()
                chrome_opt.add_argument(
                    'user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"')
                chrome_opt.add_argument('window-size=1200x1050')
                chrome_opt.add_experimental_option('excludeSwitches', ['enable-automation'])
                chrome_opt.add_argument('blink-settings=imagesEnabled=false')
                chrome_opt.add_argument('--disable-infobars')
                chrome_opt.add_argument("--headless")
                chrome_opt.add_argument('--disable-gpu')
                chrome_opt.add_argument('--no-sandbox')
                chrome_opt.add_argument("--proxy-server=%s" % func1(ip_list))
                browser = webdriver.Chrome(
                    executable_path="./chromedriver.exe",
                    options=chrome_opt)
                # driver = webdriver.Chrome(options=chrome_opt)
                # browser.implicitly_wait(20)
                browser.get("http://diaocha.iphouse.com.cn/s/aANnea/")
                # time.sleep(1)
    
                re.search(r'下一页(.*)', browser.page_source).group()
                flag = True
            except Exception as e:
                # with open("error.txt", "a+", encoding="utf-8") as fp:
                #     fp.write(json.dumps(value,ensure_ascii=False))
                #     fp.write("
    ")
                print(e)
                for i in range(3):
                    try:
                        chrome_opt = webdriver.ChromeOptions()
                        chrome_opt.add_argument(
                            'user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"',
                        )
                        chrome_opt.add_argument('window-size=1200x1050')
                        chrome_opt.add_experimental_option('excludeSwitches', ['enable-automation'])
                        chrome_opt.add_argument('blink-settings=imagesEnabled=false')
                        chrome_opt.add_argument('--disable-infobars')
                        chrome_opt.add_argument("--headless")
                        chrome_opt.add_argument('--disable-gpu')
                        chrome_opt.add_argument('--no-sandbox')
                        chrome_opt.add_argument("--proxy-server=%s" % func1(ip_list))
                        browser = webdriver.Chrome(
                            executable_path="./chromedriver.exe",
                            options=chrome_opt)
                        # driver = webdriver.Chrome(options=chrome_opt)
                        # browser.implicitly_wait(20)
                        browser.get("http://diaocha.iphouse.com.cn/s/aANnea/")
                        # time.sleep(1)
                        re.search(r'下一页(.*)', browser.page_source).group()
                    except Exception as e:
                        print("desc_", e)
                    if browser and browser.page_source and re.search(r'下一页(.*)', browser.page_source):
                        flag = True
                        break
            if flag:
                # 正常任务执行状态    
    Code
  • 相关阅读:
    UTF-8 的理解
    P4779 【模板】单源最短路径(标准版)
    Proj THUDBFuzz Paper Reading: FuzzFactory: Domain-Specific Fuzzing with Waypoints
    记一次ctf文件上传
    使用vue创建项目的详细步骤
    Vue进行事件处理的方法(指南
    规则引擎-可视化平台-构思1
    常用正则校验
    tomcat无法启动socket bind failed 的解决方法
    mysql修改root密码
  • 原文地址:https://www.cnblogs.com/xinzaiyuan/p/14093444.html
Copyright © 2011-2022 走看看