简体   繁体   中英

Errors with Selenium and Python and Using Chrome Driver

EDIT: The code is failing after the first line. I have reinstalled Google Chrome, reinstalled the webdriver, and selenium, however I can't seem to resolve the issue. The screenshot is attached. I'm also Image here! MacOS. Thank you @Dimitri T and @Omer Tekbiyik for your assistance thus far!

I am trying to use selenium and python using chromedriver, but I can't seem to get past a string of errors. I've troubleshooted using just about everything. Any help would be greatly appreciated!


from selenium import webdriver
# os.environ["webdriver.chrome.driver"] = chromedriver
# browser = webdriver.Chrome(chromedriver)
# browser.get("https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-# ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main")

# title = browser.title
# print(title)

Here is the Code I have tried. I've also tried this...

from selenium import webdriver

# browser = webdriver.Chrome()
# browser.get("https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-# # ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main")

# title = browser.title
# print(title)

I expect it to launch a webpage, however, I just get a string of errors.

Traceback (most recent call last):
  File "/Users/trapbookpro/Downloads/PythonLoginScripts/yes.py", line 1, in <module>
    from selenium import webdriver
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 29, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 21, in <module>
    import copy
  File "/Users/trapbookpro/Downloads/PythonLoginScripts/copy.py", line 10, in <module>
    lst1()

You just need to add driver path like:

driver_path = r'your driver path'
browser = webdriver.Chrome(executable_path=driver_path)

and get titles like :

from selenium import webdriver

driver_path = r'your path'
browser = webdriver.Chrome(executable_path=driver_path)
browser.get("https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main")
title = browser.title
print(title)

Output :

NYU Login
  1. Let's start clean. Install Selenium package using PIP .

     pip install -U selenium 
  2. Download and install Chrome
  3. Download Chromedriver (make sure to choose the matching version for your Chrome browser version)
  4. Amend your code to look like:

     from selenium import webdriver browser = webdriver.Chrome("c:\\\\path\\\\to\\\\chromedriver.exe") browser.get( "https://newclasses.nyu.edu/portal/site/a3aa9fb7-82a4-4b7e-ac96-2e50b60cbbbc/tool/b81f9600-6b1e-452f-9e1a-ea4af0d2fb4a/main") title = browser.title print(title) browser.quit() 
  5. That's it, your script should be working now:

    在此输入图像描述

More information including installation, configuration steps and a sample project: Selenium With Python

I found a solution to this problem! After experimenting with Jupyter I found a way to make this script work!

sudo -H pip3 install -U selenium
sudo -H pip3 install urllib3
sudo easy_install selenium 

This works perfectly and also running my script in python3 allowed me to successfully run this script. Thank you, everyone, for everything!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM