My code:
我的代码是:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path='./chromedriver.exe', options=option)
driver.get('https://www.google.com/')
Output:
产出:
WebDriver.__init__() got an unexpected keyword argument 'executable_path'
I'm trying to create a script to log in to a website. When I try to run this script, it gives me this error:
WebDriver.__init__() got an unexpected keyword argument 'executable_path'
我正在尝试创建一个登录网站的脚本。当我尝试运行此脚本时,出现以下错误:WebDriver.__init__()获得意外的关键字参数‘Executable_Path’
更多回答
This is due to changes in selenium
4.10.0
:
https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e
这是由于Selify 4.10.0:https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e中的更改所致
Note that executable_path
was removed.
请注意,删除了EXECUTABLE_PATH。
If you want to pass in an executable_path
, you'll have to use the service
arg now.
如果您想要传入一个EXECUTABLE_PATH,您现在就必须使用服务arg。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path='./chromedriver.exe')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
Note: Remove executable_url
from the argument, because you have installed the latest version of Selenium if you have selenium above the 4.6.0
you don't need to add executable_url
and in the latest version of Selenium you don't need to download webdriver.
注意:从参数中删除ecutable_url,因为您已经安装了最新版本的Selify,如果您的Selify版本高于4.6.0,则不需要添加Executable_url,并且在最新版本的Selify中,您不需要下载Web驱动程序。
just copy the below code and run the your python file simple
只需复制以下代码并运行您的简单的python文件
from selenium import webdriver
driver=webdriver.Chrome()
driver.get("https://www.facebook.com/")
Just remove executable_path
(see below), if you do not wish to set the driver.exe
path manually. With latest selenium(v4.6.0
and onwards), its in-built tool known as SeleniumManger
can download and handle the driver.exe
if you do not specify.
如果不希望手动设置driver.exe路径,只需删除EXECUTABLE_PATH(见下文)即可。在最新的Selenium(V4.6.0及更高版本)中,其内置工具SeleniumManger可以下载并处理driver.exe,如果您不指定的话。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = option)
driver.get('https://www.google.com/')
the latest selenium doesnt require a webdriver. you can remove executable_url from the argument, because you have installed the latest version of Selenium
最新的Selify不需要Web驱动程序。您可以从参数中删除executable_url,因为您已经安装了最新版本的Selify
You can try this method
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
I helped solve this in this github post: https://github.com/clemfromspace/scrapy-selenium/issues/128. Please note I'm using scrapy to create web scrapers and Selenium to interact with the website.
我在GitHub的这个帖子中帮助解决了这个问题:https://github.com/clemfromspace/scrapy-selenium/issues/128.请注意,我正在使用SCRAPY创建网络刮板,并使用Selify与网站进行交互。
- go to ton77v's commit 5c3fe7b and copy his code in middlewares.py
- replace the middlewares.py code under the scrapy_selenium package on your local machine (for me, it was in C:/Users//AppData/Local/anaconda3/Lib/site-packages/scrapy_selenium/middlewares.py)
- [optional]: I had to !pip install webdriver-manager as well
for your scrapy spider, you need to modify the settings.py file (this is part of the configuration files that appear when you start a scrapy project like items.py, middlewares.py, pipelines.py, and settings.py). Add the following lines of code into the settings.py file
SELENIUM_DRIVER_NAME = 'chrome'
SELENIUM_DRIVER_EXECUTABLE_PATH = None #not actually necessary, will work even if you comment this line out
SELENIUM_DRIVER_ARGUMENTS=[] #put '--headless' in the brackets to prevent browser popup
- then enter
scrapy runspider <scraper_name>.py
in your terminal and enjoy!
Quick explanation of what's happening:
快速解释正在发生的事情:
- you're getting scrapy to install the BrowserDriverManager and don't have to specify the BrowserDriverManager location anymore
- the beauty is that after the first BrowserDriverManager installation, it remembers the installation location and uses the installed BrowserDriverManager for subsequent runs
- You can adapt the scraper to open other browsers by modifying middlewares.py file (get ChatGPT to do it for you XD) and changing SELENIUM_DRIVER_NAME = (browser name)
更多回答
This worked for me, but only once I also implemented the answer by @Arsalan Ahmend
这对我很有效,但只有一次我也实现了@Arsalan Ahmend的答案
This helped thanks
这很有帮助,谢谢
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
您的答案可以通过其他支持信息来改进。请编辑以添加更多详细信息,如引用或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。
我是一名优秀的程序员,十分优秀!