当前位置:网站首页>已解决(selenium 操作火狐Firefox浏览器报错)AttributeError: ‘WebDriver’ object has no attribute ‘execute_cdp_cmd’
已解决(selenium 操作火狐Firefox浏览器报错)AttributeError: ‘WebDriver’ object has no attribute ‘execute_cdp_cmd’
2022-07-23 13:25:00 【无 羡ღ】
已解决(selenium 操作火狐Firefox浏览器使用 stealth.min.js文件隐藏浏览器指纹特征报错)AttributeError: ‘WebDriver’ object has no attribute ‘execute_cdp_cmd’
报错代码
我的代码如下,想用stealth.min.js文件隐藏浏览器指纹特征,之前用Chrome浏览器都没有问题:
from selenium import webdriver
# 1. 初始化配置对象
options = webdriver.FirefoxOptions()
# 2. 无界面模式
options.add_argument('--headless')
options.add_argument('--disable-gpu')
# 3. 添加请求头伪装浏览器
options.add_argument(
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0')
# 4. 告诉浏览器去掉了webdriver痕迹
options.add_argument("--disable-blink-features=AutomationControlled")
# 5. 不加载图片提高访问速度
options.add_argument('blink-settings=imagesEnabled=false')
options.add_argument('--disable-images')
driver = webdriver.Firefox(options=options)
# 6. 隐式等待10秒
driver.implicitly_wait(10)
# 7. 隐藏浏览器指纹
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('1.png')
driver.quit()
报错信息:
Traceback (most recent call last):
File "E:/Python学习/1.py", line 23, in <module>
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
AttributeError: 'WebDriver' object has no attribute 'execute_cdp_cmd'

报错翻译
报错内容翻译:属性错误 :“WebDriver”对象没有属性“execute\u cdp\u cmd”,及没有那个方法无法使用
报错原因
报错原因:cdp即Chrome DevTools Protocal, Chrome开发者工具协议,只适用于 Chrome浏览器,其他浏览器并不能使用,但我试过Edge浏览器也可以用
解决方法
1. 去掉报错代码不隐藏浏览器指纹
2. 切换成Chrome谷歌浏览器或者Edge浏览器使用stealth.min.js文件隐藏浏览器指纹特征
边栏推荐
猜你喜欢

go run,go build,go install有什么不同

百度编辑器上传图片设置自定义目录

Deep learning convolutional neural network paper study alexnet

微信小程序wx.hideLoading()会关闭toast提示框

距离IoU损失:包围盒回归更快更好的学习(Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression)

Detector: detect objects with recursive feature pyramid and switchable atolos convolution

TS encapsulates the localstorage class to store information

TOPSIS法(MATLAB)

Heartless sword English Chinese bilingual poem 006. to my wife

Tensorflow2.x actual combat series softmax function
随机推荐
Direct exchange
SQL156 各个视频的平均完播率
微信小程序class绑定,怎么绑定2个变量
Nifi 1.16.3 cluster setup +kerberos+ user authentication
YOLOV7
Notes on Microcomputer Principle and technical interface
层次分析法(MATLAB)
阿里平头哥CPU技术生态负责人陈炜:平头哥的发展之路
(resolved) idea compilation gradle project prompt error no symbol found
docker 安装redis
[note] linear regression
IE盒模型和标准盒模型
同花顺上选择券商,网上客户经理开户安全吗
Bag of tricks for image classification "with convolutional neural networks"
Liupeng, vice president of copu: China's open source has approached or reached the world's advanced level in some areas
Tan Zhangxi, director of risc-v Foundation: risc-v has gradually expanded from the edge to the center
Scale Match for Tiny Person Detection
Satisfiability of the equation of leetcode
僧多粥少?程序员要怎样接私活才能有效提高收入?
2022-7-22 面经复习+简单题目整理