禁用Selenium Chrome驱动程序中的日志记录

时间:2018-12-13 12:46:53

标签: selenium scrapy selenium-chromedriver

我在Scrapy中使用硒,它会产生过多的日志。 enter image description here 我之前尝试过SO提供的几种解决方案,但没有一个起作用。 基本上,我尝试在options中禁用它,并传递service-argument以将日志写入文件。在两种情况下,日志在执行时仍会打印。我该如何解决?

options = Options()
options.headless = True
# options.add_argument('--disable-logging')
self.driver = webdriver.Chrome(r'C:\Python3\selenium\webdriver\chromedriver_win32\chromedriver.exe', chrome_options=options, service_args=["--verbose", "--log-path=D:\\qc1.log"])   

我还尝试将服务路径设置为NULL(运行Windows)

self.driver = `webdriver.Chrome(r'C:\Python3\selenium\webdriver\chromedriver_win32\chromedriver.exe', chrome_options=options, service_log_path='NUL')`

解决方案: 感谢-@Manmohan_singh和The only working answer so far 添加此

chrome_options.add_argument("--log-level=3") to shut the logging.
self.driver = webdriver.Chrome(r'C:\Python3\selenium\webdriver\chromedriver_win32\chromedriver.exe', chrome_options=options) 

希望这对将来很有用,因为可能没有重复的主题对我没有帮助,并且Stack主持人似乎并没有仔细阅读这些帖子。

0 个答案:

没有答案