怎么把selenium的这个d:\Code\Python\Reptile\Study\douying\抖音2.0.py:44: DeprecationWarning: executable_path has been deprecated, please pass in a Service object bro = webdriver.Chrome(executable_path='../stu/chromedriver',options=option,chrome_options=chrome_options) d:\Code\Python\Reptile\Study\douying\抖音2.0.py:44: DeprecationWarning: use options instead of chrome_options bro = webdriver.Chrome(executable_path='../stu/chromedriver',options=option,chrome_options=chrome_options) 警告日志关闭
时间: 2023-09-30 22:07:26 浏览: 55
你可以通过设置logging的级别来控制警告日志信息的输出。以下是一个例子,演示如何将输出级别设置为ERROR,从而关闭selenium的警告日志信息输出:
```python
import logging
logging.getLogger('selenium').setLevel(logging.ERROR)
```
在这个例子中,我们将selenium的日志级别设置为ERROR,这意味着只有ERROR及以上级别的日志信息才会被输出,而WARNING和INFO级别的日志信息将被忽略。这样做可以减少输出信息,从而提高程序的运行效率。
注意,这只能控制selenium的警告日志信息输出,而不能关闭所有Python的警告日志输出。如果你想关闭所有Python的警告日志输出,可以将根Logger的级别设置为ERROR:
```python
logging.getLogger().setLevel(logging.ERROR)
```
这样做将会关闭所有Python的警告日志输出,包括selenium的警告日志输出。
相关问题
PS C:\Users\chenxianqiang> & D:/python3/python.exe d:/pythonbaijiahao/baijiahao.py d:\pythonbaijiahao\baijiahao.py:22: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(r"D:\python3\Scripts\chromedriver.exe")
这段代码中同样出现了一个 DeprecationWarning,警告您使用的是已过时的方法。建议您改用新的方法来替代,例如:
```python
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
```
这里使用 webdriver_manager 来安装和管理 ChromeDriver,避免了手动下载和指定 chromedriver 路径的麻烦。
D:\Python\Lib\site-packages\selenium\webdriver\common\driver_finder.py
D:\Python\Lib\site-packages\selenium\webdriver\common\driver_finder.py 是 Selenium 的一个模块,它主要用于在系统中查找可以使用的浏览器驱动程序,并返回可用的驱动程序的路径。在 Selenium 中,使用浏览器驱动程序是与浏览器进行交互的基础。而 driver_finder.py 则是实现了根据系统平台和用户设置来搜索驱动程序的功能。它会根据不同的浏览器类型和版本,搜索并返回可用的驱动程序路径。