简体   繁体   中英

name error while trying selenium to open google

im trying the selenium webdriver to open google via chrome but im getting an error

 from selenium import webdriver

driver = web.driver.Chrome(r'C:\Users\sahay\Downloads\chromedriver.exe')
driver.maximize_window()

driver.get("http://www.google.com")

this is the error which im getting:

Traceback (most recent call last): File "C:/Users/sahay/Desktop/python/save/open_google.py", line 3, in driver = web.driver.Chrome(r'C:\Users\sahay\Downloads\chromedriver.exe') NameError: name 'web' is not defined

thanks for helping a fellow noob out!

You have 2 mistakes, please correct it as below and you'll be good to go.

from selenium import webdriver

driver = webdriver.Chrome('/path/to/chromedriver')
driver.get('http://www.google.com/');

show this alternative way: Python webbrowser.open() to open Chrome browser

I use it for windows, if you have another system, comment the windows link line and active the line of your system

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)

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