def run(self): """ Downloads, unzips and installs chromedriver. If a chromedriver binary is found in PATH it will be copied, otherwise downloaded. """ chromedriver_version='78.0.3904.11' chromedriver_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'chromedriver_binary') chromedriver_filename = find_binary_in_path(get_chromedriver_filename()) if chromedriver_filename and check_version(chromedriver_filename, chromedriver_version): print("\nChromedriver already installed at {}...\n".format(chromedriver_filename)) new_filename = os.path.join(chromedriver_dir, get_chromedriver_filename()) self.copy_file(chromedriver_filename, new_filename) else: chromedriver_bin = get_chromedriver_filename() chromedriver_filename = os.path.join(chromedriver_dir, chromedriver_bin) if not os.path.isfile(chromedriver_filename) or not check_version(chromedriver_filename, chromedriver_version): print("\nDownloading Chromedriver...\n") if not os.path.isdir(chromedriver_dir): os.mkdir(chromedriver_dir) url = get_chromedriver_url(version=chromedriver_version) try: response = urlopen(url) if response.getcode() != 200: raise URLError('Not Found') except URLError: raise RuntimeError('Failed to download chromedriver archive: {}'.format(url)) archive = BytesIO(response.read()) with zipfile.ZipFile(archive) as zip_file: zip_file.extract(chromedriver_bin, chromedriver_dir) else: print("\nChromedriver already installed at {}...\n".format(chromedriver_filename)) if not os.access(chromedriver_filename, os.X_OK): os.chmod(chromedriver_filename, 0o744) build_py.run(self)
def browser(): with webdriver.Chrome(get_chromedriver_filename()) as browser: print("Creating a Chrome Browser Instance") browser.maximize_window() browser.get("https://dev.to/") print("Opening " + browser.current_url) yield browser
def __find_exe(self): return join(dirname(chromedriver_binary.__file__), get_chromedriver_filename())