![](/img/trans.png)
[英]Python Selenium - error while trying to find element by class name
[英]name error while trying selenium to open google
我正在嘗試 selenium 網絡驅動程序通過 chrome 打開谷歌,但我收到錯誤
from selenium import webdriver
driver = web.driver.Chrome(r'C:\Users\sahay\Downloads\chromedriver.exe')
driver.maximize_window()
driver.get("http://www.google.com")
這是我得到的錯誤:
回溯(最近一次通話最后):文件“C:/Users/sahay/Desktop/python/save/open_google.py”,第 3 行,在驅動程序 = web.driver.Chrome(r'C:\Users\sahay\Downloads \chromedriver.exe') NameError: name 'web' is not defined
謝謝你幫助一個菜鳥!
您有 2 個錯誤,請按以下方式更正,您會很好地適應 go。
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver')
driver.get('http://www.google.com/');
顯示這種替代方式: Python webbrowser.open() 打開 Chrome 瀏覽器
我將它用於 windows,如果您有其他系統,請評論 windows 鏈接線並激活您系統的線
import webbrowser
url = 'http://docs.python.org/'
# MacOS
#chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
# Windows
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
# Linux
# chrome_path = '/usr/bin/google-chrome %s'
webbrowser.get(chrome_path).open(url)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.