簡體   English   中英

Selenium和Python的錯誤以及使用Chrome驅動程序

[英]Errors with Selenium and Python and Using Chrome Driver

編輯:第一行后代碼失敗。 我重新安裝了谷歌Chrome,重新安裝了webdriver和selenium,但我似乎無法解決這個問題。 屏幕截圖已附上。 我也是這里的形象! 蘋果系統。 感謝@Dimitri T和@Omer Tekbiyik為您提供的幫助!

我試圖使用chromedriver使用selenium和python,但我似乎無法通過一系列錯誤。 我使用幾乎所有東西進行了故障排除。 任何幫助將不勝感激!


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)

這是我試過的代碼。 我也試過這個......

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)

我希望它能夠啟動一個網頁,但是,我只是遇到了一系列錯誤。

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()

您只需添加驅動程序路徑,如:

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

並獲得如下標題:

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)

輸出:

NYU Login
  1. 讓我們開始干凈吧。 使用PIP安裝Selenium軟件包

     pip install -U selenium 
  2. 下載並安裝Chrome
  3. 下載Chromedriver (確保為您的Chrome瀏覽器版本選擇匹配版本)
  4. 修改您的代碼看起來像:

     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. 就是這樣,你的腳本現在應該正常工作:

    在此輸入圖像描述

更多信息,包括安裝,配置步驟和示例項目: Selenium With Python

我找到了解決這個問題的方法! 在嘗試使用Jupyter之后,我找到了一種方法來使這個腳本工作!

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

這非常有效,並且在python3中運行我的腳本允許我成功運行此腳本。 謝謝大家,謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM