selenium优雅打开并关闭网页
- with 上下文管理器
-
def __enter__(self): return self def __exit__(self, exc_type: typing.Optional[typing.Type[BaseException]], exc: typing.Optional[BaseException], traceback: typing.Optional[types.TracebackType]): self.quit()
- 优雅打开并关闭
from selenium import webdriver with webdriver.Chrome('../chromedriver.exe') as dirver: dirver.get('https://www.baidu.com/') from time import sleep sleep(5)
本文来自博客园,作者:手可摘星辰/*,转载请注明原文链接:https://www.cnblogs.com/u-damowang1/p/17540901.html