【发布时间】:2020-08-01 15:11:23
【问题描述】:
我正在使用 PyCharm,并且正在关注 YouTube 教程。复制他们的方法后,我没有得到想要的结果。
from selenium import webdriver
class InstaBot:
def __init__(self):
self.driver = webdriver.Chrome()
self.driver.get("https://instagram.com")
InstaBot()
Traceback (most recent call last):
File "/Users/prxthm/PycharmProjects/untitled1/bot.py", line 10, in <module>
InstaBot()
File "/Users/prxthm/PycharmProjects/untitled1/bot.py", line 7, in __init__
self.driver = webdriver.Chrome()
AttributeError: 'function' object has no attribute 'Chrome'
【问题讨论】:
-
你看到了什么错误?
-
您必须添加完整路径,直到 chromedriver.exe。我相信您只是去了文件夹并忘记在最后附加文件名。
-
OK - 所以在您的最新代码中,没有定义到 chromedriver.exe 位置的路径。你把那个去掉了吗? - 运行代码时出现什么错误?
-
我更新了错误,请问如何定义chromedriver.exe的路径
-
您定义了以下答案中提到的路径...
browser = webdriver.Chrome('/full/path/to/your/exe/chromedriver.exe')...当您运行pip show selenium时,输出是什么?最后,您的 chromedriver 版本是什么,它与您安装的 chrome 匹配吗?
标签: python-3.x selenium webdriver