使用with 打开一个网页
from selenium import webdriver from time import sleep with webdriver.Chrome() as driver: # with 上下文管理协议 # 目的在于从流程图中把try, except 和finally 关键字和资源分配释放相关代码统统去掉, # 简化try….except….finlally的处理流程 driver.get('https://www.baidu.com/') sleep(5)
from selenium import webdriver from time import sleep with webdriver.Chrome() as driver: # with 上下文管理协议 # 目的在于从流程图中把try, except 和finally 关键字和资源分配释放相关代码统统去掉, # 简化try….except….finlally的处理流程 driver.get('https://www.baidu.com/') sleep(5)