1、
from selenium import webdriver
url=r'http://www.baidu.com'
# 如果只有一个谷歌,直接初始化谷歌的浏览器对象
driver = webdriver.Chrome()
2、
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from time import sleep
# 指定谷歌的位置
chrome_location = r'D:\python\chrome114\chrome-win\chrome.exe'
options = webdriver.ChromeOptions()
options.binary_location = chrome_location
driver=webdriver.Chrome(options=options)
driver.get(url)
sleep(3)
3、
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from time import sleep
# 指定谷歌的位置
chrome_location = r'D:\python\chrome114\chrome-win\chrome.exe'
options = webdriver.ChromeOptions()
options.binary_location = chrome_location
#driver=webdriver.Chrome(options=options)
# 指定Chromedriver驱动位置:service参数(注意驱动程序如果放置到了python安装目录下,可以不使用service参数)
driver_location=r'D:\python\chromedriver.exe'
service=Service(driver_location)
driver=webdriver.Chrome(options=options,service=service)
driver.get(url)
sleep(3)