当前位置:网站首页>已解决(selenium操作火狐浏览器报错)TypeError: __init__() got an unexpected keyword argument ‘firefox_options‘
已解决(selenium操作火狐浏览器报错)TypeError: __init__() got an unexpected keyword argument ‘firefox_options‘
2022-07-21 09:28:00 【无 羡ღ】
已解决(selenium操作火狐浏览器报错)TypeError: init() got an unexpected keyword argument ‘firefox_options‘
报错代码
我的代码:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
# 1. 初始化配置对象
options = Options()
# 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(firefox_options=options)
# 6. 隐式等待10秒
driver.implicitly_wait(10)
driver.get('https://bot.sannysoft.com/')
driver.save_screenshot('2.png')
driver.quit()
报错信息:
Traceback (most recent call last):
File "E:/Python/test5.py", line 17, in <module>
driver = webdriver.Firefox(firefox_options=options)
TypeError: __init__() got an unexpected keyword argument 'firefox_options'
报错翻译
报错内容翻译:类型错误:获得意外的关键字参数“firefox\u options”
报错原因
报错原因:
Selenium 3.8中不推荐使用浏览器选项参数firefox_options。
浏览器选项参数现在在驱动程序中标准化为options
。firefox_options、chrome_options和ie_options现在不推荐使用
解决方法
修改代码:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
# 1. 初始化配置对象
options = Options()
# 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)
driver.get('https://bot.sannysoft.com/')
driver.save_screenshot('2.png')
driver.quit()
高亮的报错参数消失了:
边栏推荐
- [Development Tutorial 4] crazy shell · humanoid hip-hop robot PC upper computer online debugging
- Solve the error omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized
- (闲暇)LeetCode_7. 整数反转
- Codeforces Round #809 (Div. 2) - C, D1
- 电脑是怎样上网的 (二) 从网线到网络设备
- MySQL insert data error
- Sentinel容错规则持久化
- Objet js: détection de l'existence d'attributs
- 一年时间过去了,LiveData真的被Flow代替了吗? LiveData会被废弃吗?
- [academic related] recommended by Chen Tianqi, Wang William and others: a little advice from the winner of ACL best paper award to new researchers
猜你喜欢
SQL基本语句练习
Hcip day 10 notes
电脑是怎样上网的 (二) 从网线到网络设备
HCIP第八天笔记
Gateway route assertion factory, filter factory, cross domain processing
SkyWalking服务端的搭建、微服务接入SkyWalking
On Newton iteration
[intensive reading of thesis]attention is all you need
ByteDance confirmation will be self-developed chip: for internal use only; Musk: I have uploaded my brain to the cloud; Go language product head leaves | geek headlines
HCIP第十天笔记
随机推荐
Seata details of distributed transactions
mysql进阶(十四) 批量更新与批量更新多条记录的不同值实现方法
Static distribution and dynamic distribution in trust
[自然语言处理] 预训练词向量百度云下载 [Word2Vec, Glove, FastText]
The quality section of the development period is selected from "smell defects and be happy" (this book can be downloaded for free)
Practice of large-scale [project management]
[learning notes] on Gaussian integer
Add two numbers leecode2
基于三维GIS的场数据模型研究与实践
Nacos配置中心中配置文件的创建、微服务读取nacos配置中心
OSPF综合实验
How computers access the Internet (III) packet header packaging and access network and network operators
Hmailserver enables authentication to prevent spam harassment
SQL basic statement exercise
3625. Power
学习STM32,从HAL库的框架设计开始
Grasp the drive of morning meeting 【 target management 】
CTF problem solving ideas
The sum of the last three numbers
rust中的静态分发和动态分发