如何限制chromedriver loggin?

时间:2018-09-16 12:37:21

标签: python selenium

我已经使用chromedriver日志记录来获取这样的http状态代码

self.d = DesiredCapabilities.CHROME
    self.d['loggingPrefs'] = {'performance': 'ALL'}

    for i in range(self.max_thread):
        driver = webdriver.Chrome(executable_path=self.chromedir,
                                  service_args=["--verbose",
                                                "--log-path=chromedriver.log"],
                                  desired_capabilities=self.d,
                                  chrome_options=self.options)
        self.drivers.append(driver)
def get_status_code(self,driver):
    performance_log = driver.get_log('performance')
    code = 418
    for log in performance_log:
        try:
            if json.loads(log['message'])['message']['params']['response']['url'] == driver.current_url:
                code = int(json.loads(log['message'])['message']['params']['response']['status'])
        except KeyError:
            pass
    if code == 418:
        self.logger.critical("Fail to get status code : %s"%driver.current_url)
        with open("exception.txt","a") as f:
            f.write(driver.current_url+"\n")
    return code

,而chromedriver.log越来越大,超过1GB。我如何将其限制在10MB以下?

0 个答案:

没有答案