[英]AttributeError: module 'selenium.webdriver' has no attribute 'webdriver'
I've installed selenium correctly as well as the chromium webdriver for selenium and I keep getting the following error我已经正确安装了硒以及硒的铬网络驱动程序,但我不断收到以下错误
Traceback (most recent call last):
File "C:/Users/Turtle/PycharmProjects/SpotifyWebscraper/seleniumTest.py", line 3, in <module>
driver = webdriver.chrome()
TypeError: 'module' object is not callable
here is my code:这是我的代码:
from selenium import webdriver
driver = webdriver.chrome()
driver.get("htts://www.google.com")
print(driver.title)
print(driver.current_url)
driver.quit
I've checked in the folders correctly and the files seem to be in the right positions:我已正确签入文件夹,文件似乎位于正确的位置:
C:\Users\Turtle\AppData\Local\Programs\Python\Python38\Lib\site-packages\selenium-4.0.0a3-py3.8.egg\selenium\webdriver\chromium
contains webdriver.py包含 webdriver.py
If you look at the way Selenium imports the various flavours of webdriver
to selenium.webdriver
you can see that the import you want is Chrome
如果您查看 Selenium 将各种风格的
webdriver
导入selenium.webdriver
您可以看到您想要的导入是Chrome
from .firefox.webdriver import WebDriver as Firefox # noqa
from .chrome.webdriver import WebDriver as Chrome # noqa
So you would do driver = webdriver.Chrome()
or if you want Firefox, webdriver.Firefox()
所以你会做
driver = webdriver.Chrome()
或者如果你想要 Firefox, webdriver.Firefox()
By doing webdriver.chrome()
you're importing & calling the actual chrome
module通过执行
webdriver.chrome()
您正在导入和调用实际的chrome
模块
In terms of your new error, you need to download the chromedriver executable and make sure it's in a folder which is available to python (included in your PATH
).就您的新错误而言,您需要下载 chromedriver 可执行文件并确保它位于 python 可用的文件夹中(包含在您的
PATH
)。 You can download chromedriver here;你可以在这里下载 chromedriver; https://sites.google.com/a/chromium.org/chromedriver/downloads
https://sites.google.com/a/chromium.org/chromedriver/downloads
The error in your title is different than the one in your post.您标题中的错误与您帖子中的错误不同。
TypeError: 'module' object is not callable
chrome
should be capitalized in webdriver.chrome()
: chrome
应该在webdriver.chrome()
大写:
driver = webdriver.Chrome() # .Chrome(), not .chrome()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.