我无法使用Python Selenium自动登录网站

我正在尝试使用python脚本自动连接到网站。但是不知何故,这使我出错了。

我正在使用的代码:

from selenium import webdriver
from getpass import getpass
username = input("Enter you CUID:")
password = getpass("Enter you CUID password:")
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
driver = webdriver.Chrome(chrome_options=options)
driver1 = webdriver.Chrome("C:\\Users\\PrakashJha\\Documents\\webdriver\\chromedriver_win32\\chromedriver")
driver1.get("https://directory.corp.intranet/cmsviewer/login.html?page=/cmsviewer/MAL/index.html%3Fkey%3DY8P-CRS")
cuid_user = driver1.find_element_by_name("f_loginname")
cuid_user.send_keys(username)
password_cuid = driver1.find_element_by_xpath("/html/body/table[3]/tbody/tr[1]/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td[1]/form/table/tbody/tr[2]/td[2]/input")
password_cuid.send_keys(password)
enter_button = driver1.find_elements_by_name("frn_login")
enter_button.submit()*

我尝试连接的站点需要VPN访问。

我收到的错误是:

C:\Users\PrakashJha\PycharmProjects\new\venv\Scripts>python Cms_connect.py
Enter you CUID:acxxxx
Enter you CUID password:
Cms_connect.py:10: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(chrome_options=options)
Traceback (most recent call last):
  File "C:\Users\PrakashJha\PycharmProjects\new\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\PrakashJha\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\PrakashJha\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, 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 "Cms_connect.py", line 10, in <module>
    driver = webdriver.Chrome(chrome_options=options)
  File "C:\Users\PrakashJha\PycharmProjects\new\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\PrakashJha\PycharmProjects\new\venv\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

enter image description here

请帮忙

评论
  • Nicol
    Nicol 回复

    提供chromedriver的完整路径,直到.exe

    例:

    driver1 = webdriver.Chrome("C:\\Users\\PrakashJha\\Documents\\webdriver\\chromedriver_win32\\chromedriver.exe")