chromedriver headless 模式屏蔽日志

本文介绍如何在Chromedriver的headless模式下屏蔽过多的日志信息,通过设置日志等级为3,可以有效过滤掉error级别的日志,减少无用输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

headless无头浏览器模式下有很多日志信息,如下,

将日志等级设定为 3 即可

chrome_options.add_argument('log-level=3')
#info(default) = 0
#warning = 1
#LOG_ERROR = 2
#LOG_FATAL = 3

DevTools listening on ws://127.0.0.1:55019/devtools/browser/472a41e1-3529-48c2-8f96-4b2ae0861b12
[1217/154711.234:INFO:CONSOLE(28)] "[ Logic-error ]  [object Object]", source: https://webresource.c-ctrip.com/code/cquery/cQuery_110421.js (28)
[1217/154711.289:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://baidu.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and
https://www.chromestatus.com/feature/5633521622188032.", source: https://www.ctrip.com/ (0)
[1217/154711.401:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://cdid.c-ctrip.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://www.ctrip.com/ (0)
[1217/154712.598:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://doubleclick.net/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://www.ctrip.com/ (0)
[1217/154713.180:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://gtags.net/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and
https://www.chromestatus.com/feature/5633521622188032.", source: https://www.ctrip.com/ (0)
[1217/154717.774:INFO:CONSOLE(1997)] "Mixed Content: The page at 'https://www.ctrip.com/' was loaded over a
secure connection, but contains a form that targets an insecure endpoint 'http://hotels.ctrip.com/hotel/16296689.html#ctm_ref=ctr_hp_sb_lst'. This endpoint should be made available over a secure connection.", source: https://webresource.c-ctrip.com/pub/981d5e8a/6aa58be5/e153deab/1e5e5c50.js (1997)
[1217/154717.778:INFO:CONSOLE(2153)] "Mixed Content: The page at 'https://www.ctrip.com/' was loaded over a
secure connection, but contains a form that targets an insecure endpoint 'http://hotels.ctrip.com/hotel/16296689.html#ctm_ref=ctr_hp_sb_lst'. This endpoint should be made available over a secure connection.", source: https://webresource.c-ctrip.com/pub/981d5e8a/6aa58be5/e153deab/1e5e5c50.js (2153)
[1217/154718.253:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://cdid.c-ctrip.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://hotels.ctrip.com/hotel/16296689.html#ctm_ref=ctr_hp_sb_lst (0)
[1217/154720.116:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://baidu.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and
https://www.chromestatus.com/feature/5633521622188032.", source: https://hotels.ctrip.com/hotel/16296689.html#ctm_ref=ctr_hp_sb_lst (0)
[1217/154722.558:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://doubleclick.net/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://hotels.ctrip.com/hotel/16296689.html#ctm_ref=ctr_hp_sb_lst (0)

 

selenium下webdriver一直报错

[142012:46732:0709/105443.557:ERROR:ssl_client_socket_impl.cc(1026)] handshake failed; returned -1, SSL error code 1, net_error -101

将屏蔽日志信息等级设置为3,屏蔽error即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值