#导入需要的库和模块
#根据使用的浏览器下载对应的浏览器驱动,如chromedriver,将驱动程序的路径添加到环境变量中(或指定驱动程序的路径)
# 下载需要使用的插件,将插件的路径保存到一个变量中
#指定驱动程序的路径和插件路径:
#在需要使用插件的地方进行操作,使用插件进行账号登录
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--start-maximized') # 窗口最大化
chrome_options.add_extension('D:\pythonProject\pythonProject\Scripts') # 替换为插件文件的路径
driver = webdriver.Chrome(executable='D:\pythonProject\pythonProject\Scripts', chrome_options=chrome_options)
driver.get('https://gm-portal.changyou.com/Giveaway/index')
Traceback (most recent call last):
File "D:\pythonProject\gamefish.py", line 87, in <module>
driver = webdriver.Chrome(executable='D:\pythonProject\pythonProject\Scripts', chrome_options=chrome_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: WebDriver.__init__() got an unexpected keyword argument 'executable'
,这个报错是什么原因,啊,咋解决呀
【以下回答由 GPT 生成】
这个报错是因为webdriver.Chrome()
方法中的chrome_options
参数已经被弃用,更新的方法是使用options
参数。下面是修改后的代码解决该报错:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--start-maximized')
chrome_options.add_extension('path/to/plugin/file')
# 修改这一行代码
driver = webdriver.Chrome(executable_path='path/to/chromedriver', options=chrome_options)
driver.get('https://gm-portal.changyou.com/Giveaway/index')
请将path/to/plugin/file
替换为实际插件文件的路径,将path/to/chromedriver
替换为实际的Chrome驱动程序路径。重新运行代码,应该就不会再遇到这个报错了。
【相关推荐】