当前位置:网站首页>已解决(selenium报错)AttributeError: ‘WebDriver‘ object has no attribute ‘execute_cdp_cmd‘
已解决(selenium报错)AttributeError: ‘WebDriver‘ object has no attribute ‘execute_cdp_cmd‘
2022-07-19 07:10:00 【无 羡ღ】
已解决(selenium报错)AttributeError: ‘WebDriver‘ object has no attribute ‘execute_cdp_cmd‘
报错信息
我的代码:
import time
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# 修改请求头
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36')
driver = webdriver.Chrome(chrome_options=chrome_options)
with open('stealth.min.js') as f:
js = f.read()
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": js
})
driver.get('https://bot.sannysoft.com/')
driver.save_screenshot('hidden_features.png')
报错信息:
Traceback (most recent call last):
File "E:/Python学习/1.py", line 15, in <module>
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
AttributeError: 'WebDriver' object has no attribute 'execute_cdp_cmd'
报错翻译
翻译:AttributeError:“WebDriver”对象没有属性“execute\u cdp\u cmd”
报错原因
原因:老版本的selenium没有execute_cdp_cmd属性
解决方法
1. 先把selenium卸载,代码如下:
pip uninstall selenium
2.安装最新selenium版本的,代码如下:
pip install selenium
3. 再次运行代码就成功了
边栏推荐
猜你喜欢
Conversion code from "implementation details" character index to word index
Towhee daily model weekly report
Optimisation de la Bibliothèque de base pour les sources Yum
Soc FPGA搭建工程
软件测试—学习笔记4
神经网络包括哪些网络模型 - 神经网络模型的基本原理
快解析远程服务,助力企业实现高效客户维护
TortoiseSVN Error : Previous operation has not finished; run ‘cleanup‘ if it was interrupted异常解决办法
Cake cutting problem [Olympiad Mathematics in grade two of primary school]
Chapter 3 business function development (delete the remarks of market activities)
随机推荐
分页数据的处理
gin注册自定义中间件失效
中文同义句在线转换器 - 中文同义句转换器软件
One question per day on July 17, 2022 (structure + mathematics + greed + pointer)
Presto SQL 查询时可以实现动态表名吗?
数字信号处理实验一 系统响应及系统稳定性
2022年危险化学品经营单位安全管理人员上岗证题目及模拟考试
Wechat applet realizes watch monitoring manually
对象的比较
How to import data from the client into Youxuan database through the copy command
快解析远程服务,助力企业实现高效客户维护
蓝桥杯单片机国二经验分享
大佬程序员的工作日常 | 每日趣闻
8000字超详解自定义结构体类型
Error analysis of yyyy-mm-dd
[cloud native kubernetes] binary build kubernetes cluster (Part 1) -- deploy etcd cluster and single master
2022 Shandong Province safety officer C certificate operation certificate examination questions and answers
Basic knowledge of database
神经网络包括哪些网络模型 - 神经网络模型的基本原理
Movinets series models are good helpers for real-time classified videos on mobile phones