当前位置:首页 > python > 正文内容

python selenium 怎么去掉日志输出

zhangsir3年前 (2023-03-29)python275

在使用Python Selenium时,你可以通过设置日志级别来控制日志的输出。以下是如何设置日志级别以及如何关闭Selenium日志的示例代码:

import logging
from selenium import webdriver
# 设置日志级别为 WARNING
logging.basicConfig(level=logging.WARNING)
# 禁用Selenium日志输出
options = webdriver.ChromeOptions()
options.add_argument('--disable-logging')
# 创建一个Chrome浏览器实例
driver = webdriver.Chrome(options=options)

# 在此之后的代码将不再输出Selenium日志

在这里,我们首先使用basicConfig()函数将日志级别设置为WARNING,这意味着仅输出警告及更严重的日志记录。然后,我们使用ChromeOptions()类创建一个浏览器选项实例,并通过add_argument()方法将--disable-logging参数添加到选项中,从而禁用Selenium的日志记录。最后,我们使用webdriver.Chrome()函数创建一个Chrome浏览器实例,并将选项作为参数传递给它。

注意,这个方法仅仅会禁用Selenium本身的日志输出,而不是浏览器本身的日志输出。如果你需要禁用浏览器日志,可以尝试在选项中添加--disable-logging或其他相应的参数


zhangsir版权k3防采集https://mianka.xyz

扫描二维码推送至手机访问。

版权声明:本文由zhangsir or zhangmaam发布,如需转载请注明出处。

本文链接:https://mianka.xyz/post/158.html

分享给朋友:

“python selenium 怎么去掉日志输出” 的相关文章

如何用python获取一个网页的所有连接

如何用python获取一个网页的所有连接很简单直接上代码:# -*- coding: utf-8 -*- ''' 如何用python获取一个网页的所有连接 author:zhangsir ''' imp...

Selenium添加Cookie来实现自动登录

Selenium添加Cookie来实现自动登录第一步获取你登录的cookie,以csdn为例from selenium import webdriver driver = webdriver.Chrome() driver.get('...

pip安装三方库 国内的一些镜像站点推荐

pip 国内的一些镜像站点推荐镜像套路:使用cmd;输入命令pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple 包名 即可开始安装。清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http...

计算机学习视频教程

人工智能机器学习:Python&R实践课程介绍:https://www.aihorizon.cn/1百度网盘地址: https://pan.baidu.com/s/1a743NTKFRjsgexMTagWooA?pwd=e39j动手使用Python进行自然语言处理(NLP)课程介绍:http...

python selenium 使用代理ip

代码如下:from selenium import webdriver chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument("--proxy-serv...

Linux系统下使用Python+selenium+谷歌浏览器下载文件

from seleniumwire import webdriver import time ch_options = webdriver.ChromeOptions() ch_options.add_argument("-...