Attribute Error : ‘str’ object has no attribute ‘_ignore_local_proxy’ with ChromeDriverManager

huangapple go评论66阅读模式
英文:

Attribute Error : 'str' object has no attribute '_ignore_local_proxy' with ChromeDriverManager

问题

我刚刚开始使用Selenium,已经卡在第一步了:设置驱动程序。
我一直在收到这个错误:

'str' object has no attribute '_ignore_local_proxy'。

以下是代码:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import requests

driver = webdriver.Chrome(ChromeDriverManager().install())

以及完整的错误回溯:

AttributeError                            Traceback (most recent call last)
Cell In[21], line 1
----> 1 driver = webdriver.Chrome(ChromeDriverManager().install())

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\chrome\webdriver.py:49, in WebDriver.__init__(self, options, service, keep_alive)
     45 self.keep_alive = keep_alive
     47 self.service.path = DriverFinder.get_path(self.service, self.options)
---> 49 super().__init__(
     50     DesiredCapabilities.CHROME["browserName"],
     51     "goog",
     52     self.options,
     53     self.service,
     54     self.keep_alive,
     55 )

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\chromium\webdriver.py:60, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, options, service, keep_alive)
     51 self.service.start()
     53 try:
     54     super().__init__(
     55         command_executor=ChromiumRemoteConnection(
     56             remote_server_addr=self.service.service_url,
     57             browser_name=browser_name,
     58             vendor_prefix=vendor_prefix,
     59             keep_alive=keep_alive,
...
     63     )
     64 except Exception:
     65     self.quit()

AttributeError: 'str' object has no attribute '_ignore_local_proxy'

如果可能的话,我正在使用VS Code和Python 3.11。

英文:

I've just started with Selenium and I'm already stuck at the first step: setting up the driver.
I keep getting this error:

> 'str' object has no attribute '_ignore_local_proxy'.

Here's the code :

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import requests

driver = webdriver.Chrome(ChromeDriverManager().install())

And the whole traceback :

AttributeError                            Traceback (most recent call last)
Cell In[21], line 1
----> 1 driver = webdriver.Chrome(ChromeDriverManager().install())

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\chrome\webdriver.py:49, in WebDriver.__init__(self, options, service, keep_alive)
     45 self.keep_alive = keep_alive
     47 self.service.path = DriverFinder.get_path(self.service, self.options)
---> 49 super().__init__(
     50     DesiredCapabilities.CHROME["browserName"],
     51     "goog",
     52     self.options,
     53     self.service,
     54     self.keep_alive,
     55 )

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\chromium\webdriver.py:60, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, options, service, keep_alive)
     51 self.service.start()
     53 try:
     54     super().__init__(
     55         command_executor=ChromiumRemoteConnection(
     56             remote_server_addr=self.service.service_url,
     57             browser_name=browser_name,
     58             vendor_prefix=vendor_prefix,
     59             keep_alive=keep_alive,
...
     63     )
     64 except Exception:
     65     self.quit()

AttributeError: 'str' object has no attribute '_ignore_local_proxy'

I'm using VS Code with Python 3.11, if that can somehow help.

答案1

得分: 1

这是由于selenium 4.10.0中的更改导致的:
https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

请注意,第一个参数不再是executable_path,而是options。(ChromeDriverManager().install()返回安装位置的路径。)由于selenium管理器现在已经包含在selenium 4.10.0中,您不应再使用ChromeDriverManager

from selenium import webdriver

driver = webdriver.Chrome()
# ...
driver.quit()

然而,如果您仍然希望将executable_path传递给现有的驱动程序,现在必须使用service参数:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path="PATH_TO_DRIVER")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
英文:

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

Attribute Error : ‘str’ object has no attribute ‘_ignore_local_proxy’ with ChromeDriverManager

Note that the first argument is no longer executable_path, but options. (ChromeDriverManager().install() returns the path to the install location.) Since selenium manager is now included with selenium 4.10.0, you should no longer use ChromeDriverManager at all.

from selenium import webdriver

driver = webdriver.Chrome()
# ...
driver.quit()

However, if you still want to pass in the executable_path to an existing driver, you must use the service arg now:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path="PATH_TO_DRIVER")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()

huangapple
  • 本文由 发表于 2023年6月15日 06:25:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477949.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定