原因不清楚,看别的文章说是版本问题,版本变了方法也变了
改成如下就好了:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
path = 'chromedriver.exe'
option = webdriver.ChromeOptions()
option.add_experimental_option('detach', True)
s = Service(executable_path=path)
browser = webdriver.Chrome(service=s, options=option)
url = 'https://www.baidu.com'
browser.get(url)
解决了报错:
解决 DeprecationWarning: Executable executable_path has been deprecated, please pass in a Service object in Selenium Python 问题 - 习久性成 - 博客园
解决了闪退:
selenium打开浏览器后闪退解决_蓝 风的博客-CSDN博客_selenium打开浏览器闪退