English 中文(简体)
类型Error:网络司机.__init__()在Selenium-030中举出可执行的主要词句
原标题:TypeError: WebDriver.__init__() got an unexpected keyword argument executable_path in Selenium Python

我的法典:

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/ )

产出:

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

问题回答

This is due to changes in Selenium 4.10.0: https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

“Changes_in_selenium_4_10_0

注:删除了<代码>可执行_path。

如果你希望通过<条码>可执行-path,那么现在就不得不使用<条码>服务的论点。

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()

注:从论点中删除<代码>可执行_url,因为如果您在4.6.0以上已经安装了最近版本的硫酸.,你无需添加<代码> 可执行_url,在最近版本的Selenium中,你无需下载webdriver

更正应作在印发的记录上,由有关的代表团成员一人署名,送交逐字记录处处长(C-154A)。

from selenium import webdriver

driver=webdriver.Chrome()

driver.get("https://www.facebook.com/")

仅删除<条码>可执行_path(见下文),如果你不想人工订立<条码>driver.exe<条码>。 最新版本的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/ )

我帮助解决了这一Gite Hub员额: Self.driver=司机_klass(**driver_kwargs) 类型:网络驱动器:init(a) 采用一个意想不到的关键词,可予以执行。 请使用Scrapy建立网络报废器和Selenium与网站互动。

  • 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!

迅速解释发生的情况:

  • 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)

最近的Selenium isn't需要一名网络用户。 你可以从论点中删除可执行_url,因为您已经安装了最新的硫化物。

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)

为此:

from selenium.webdriver.firefox.service import Service as FirefoxService

   firefox_profile = webdriver.FirefoxProfile()

    firefox_profile.set_preference("browser.download.folderList", 2)
    firefox_profile.set_preference("browser.download.manager.showWhenStarting", False)
    # firefox_profile.set_preference("browser.download.dir", str(output_directory))
    firefox_profile.set_preference(
        "browser.helperApps.neverAsk.saveToDisk", "application/zip")

    service = FirefoxService(firefox_profile = firefox_profile)

    browser = webdriver.Firefox(
        service= service,
        options = firefox_options
    )




相关问题
Get webpage contents with Python?

I m using Python 3.1, if that helps. Anyways, I m trying to get the contents of this webpage. I Googled for a little bit and tried different things, but they didn t work. I m guessing that this ...

What is internal representation of string in Python 3.x

In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16? The items ...

What does Python s builtin __build_class__ do?

In Python 3.1, there is a new builtin function I don t know in the builtins module: __build_class__(...) __build_class__(func, name, *bases, metaclass=None, **kwds) -> class Internal ...

what functional tools remain in Python 3k?

I have have read several entries regarding dropping several functional functions from future python, including map and reduce. What is the official policy regarding functional extensions? is lambda ...

Building executables for Python 3 and PyQt

I built a rather simple application in Python 3.1 using PyQt4. Being done, I want the application to be distributed to computers without either of those installed. I almost exclusively care about ...