当前位置:   article > 正文

Selenium取消控制台输出、忽略报警_options.add_experimental_option('excludeswitches',

options.add_experimental_option('excludeswitches', ['enable-logging'])

写了一个使用selenium的抢课python脚本,可以正常完成功能,但控制台总是打印错误信息,由于我每天都要运行并记录日志,因此看着不舒服需要屏蔽掉。报警一共有三类:

1、selenium的报警,如

ERROR:chrome_browser_main_extra_parts_metrics.cc(228)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.

等,看着很不舒服。因此上网搜索了下,只要添加这个选项就可以取消控制台报警了:

  1. options = webdriver.ChromeOptions()
  2. options.add_experimental_option('excludeSwitches', ['enable-logging'])
  3. driver = webdriver.Chrome(options=options)

2、Pytorch的报警:我的脚本识别验证码用到了ocr库easyocr,这个库调用了pytorch,会打印一些UserWarning。作为有强迫症的我同样不想看到,因此也搜索了去除方法:

  1. import warnings
  2. warnings.filterwarnings("ignore", category=UserWarning)

3、EasyOCR的报警:easyocr如果使用cpu而非gpu的话,每次识别时还会打印一条warning:

Using CPU. Note: This module is much faster with a GPU.

看着也是很烦。查看easyocr.Reader的接口可以发现,有一个verbose参数,下面判断设备是cpu还是gpu时会判断,如果verbose为True同时使用cpu则会打印这条信息。

  1. class Reader(object):
  2. def __init__(self, lang_list, gpu=True, model_storage_directory=None,
  3. user_network_directory=None, recog_network = 'standard',
  4. download_enabled=True, detector=True, recognizer=True,
  5. verbose=True, quantize=True, cudnn_benchmark=False):

所以为了不想看到这条信息,使用的时候加上一个verbose=False参数就可以了。如下所示:

reader = easyocr.Reader(['en'], gpu=False, verbose=False)

来源:

get rid of response message in python selenium - Stack Overflow

pytorch忽略user warning_Arxan_hjw的博客-CSDN博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/89875
推荐阅读
相关标签
  

闽ICP备14008679号