我正在尝试制作一个python程序,您可以将其用作instagram.com的模块。这是代码:
from selenium import webdriver
from getpass import getpass
user = input("Enter your username/email: ")
pwd = getpass(prompt="Enter your password: ")
driver = webdriver.Chrome()
driver.get("https://www.instagram.com/accounts/login/")
usr_box = driver.find_element_by_class_name("_2hvTZ.pexuQ.zyHYP")
usr_box.send_keys(user)
执行此操作后出现错误:
Traceback (most recent call last):
File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 769, in __init__
restore_signals, start_new_session)
File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1172, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\***\OneDrive\Desktop\Desktop\Python\Projects\Instagram Module.py", line 7, in <module>
driver = webdriver.Chrome()
File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
答案 0 :(得分:0)
将Chromedriver可执行文件的路径添加到Windows PATH变量中,或者在创建WebDriver
对象时可以指定可执行文件的路径:
driver = webdriver.Chrome('/path/to/chromedriver')
例如
driver = webdriver.Chrome('/Users/username/Downloads/chromedriver.exe')