Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active August 4, 2016 12:04
Show Gist options
  • Save kurozumi/89221abc124dad636250d07330ef338d to your computer and use it in GitHub Desktop.
Save kurozumi/89221abc124dad636250d07330ef338d to your computer and use it in GitHub Desktop.
【Python】Seleniumをwith構文でまとめる
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
class Firefox(object):
def __init__(self, binary=None):
if binary is None:
self.driver = webdriver.Firefox()
else:
binary = FirefoxBinary(binary)
self.driver = webdriver.Firefox(firefox_binary=binary)
def __enter__(self):
return self.driver
def __exit__(self, exception_type, exception_value, traceback):
self.driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment