英文:
Selenium with python script
问题
我是新手使用selenium,一直遇到相同的错误。我正在使用Windows操作系统,selenium版本是v4.6.0。
from selenium import webdriver
driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://www.selenium.dev/')
print(driver.title)
driver.quit()
但我一直遇到这个错误,驱动程序的路径是正确的。
错误信息
Traceback (most recent call last):
File "c:\Users\chris\development\automation\selenium\index.py", line 5, in <module>
driver = webdriver.Chrome('chromedriver.exe')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\chris\development\automation\selenium\.venv\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 49, in __init__
super().__init__(
File "C:\Users\chris\development\automation\selenium\.venv\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 60, in __init__
ignore_proxy=self.options._ignore_local_proxy,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute '_ignore_local_proxy'
英文:
I'm new to selenium and I keep running into the same error. I'm working on a windows os and have selenium version is v4.6.0.
from selenium import webdriver
driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://www.selenium.dev/')
print(driver.title)
driver.quit()
But I keep running into this error and the path for the driver is correct.
Error
Traceback (most recent call last):
File "c:\Users\chris\development\automation\selenium\index.py", line 5, in <module>
driver = webdriver.Chrome('chromedriver.exe')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\chris\development\automation\selenium\.venv\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 49, in __init__
super().__init__(
File "C:\Users\chris\development\automation\selenium\.venv\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 60, in __init__
ignore_proxy=self.options._ignore_local_proxy,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute '_ignore_local_proxy'
答案1
得分: 1
你需要一个绝对路径来使用Selenium的Chrome驱动器。
你的问题已经在这里得到了回答。
英文:
You need an absolute path to chrome driver for selenium to work.
Your question is answered here.
答案2
得分: 0
问题出在下面这行代码:
driver = webdriver.Chrome('chromedriver.exe')
如果你的selenium版本是v4.6.0
或更高版本,那么你不需要设置chromedriver.exe
的路径,所以你的代码可以简化为以下形式:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.selenium.dev/')
print(driver.title)
driver.quit()
参考链接:
- https://stackoverflow.com/a/76574264/7598774
- https://stackoverflow.com/a/76463081/7598774
- 介绍Selenium Manager
英文:
The issue is in the below line:
driver = webdriver.Chrome('chromedriver.exe')
If your selenium version is v4.6.0
or above, then you don't need to set the path for chromedriver.exe
, so your code can be simplified as below:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.selenium.dev/')
print(driver.title)
driver.quit()
References:
答案3
得分: 0
从参数中删除 executable_url
,因为如果您安装了Selenium的最新版本,且Selenium版本高于4.6.0
,则无需添加 executable_url
。在最新版本的Selenium中,您无需下载webdriver。
只需复制下面的代码并运行您的Python文件:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.facebook.com/")
英文:
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.
just copy the below code and run the your python file simple
from selenium import webdriver
driver=webdriver.Chrome()
driver.get("https://www.facebook.com/")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论