Skip to content

Instantly share code, notes, and snippets.

@NoUsername
Created December 20, 2016 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoUsername/bb716007f7ab4d2732e54f267444eedc to your computer and use it in GitHub Desktop.
Save NoUsername/bb716007f7ab4d2732e54f267444eedc to your computer and use it in GitHub Desktop.
simple script for downloading the latest chromedriver with python
import requests
from xml.dom import minidom
from subprocess import call
from distutils.version import StrictVersion
def checkValidVersion(s):
if len(s) < 1:
return None
try:
parsed = float(s[:-1])
if parsed:
# parseable, but we want the string
return s[:-1]
except ValueError:
pass
page = requests.get('https://chromedriver.storage.googleapis.com/?delimiter=/&prefix=').text
xml = minidom.parseString(page)
versionNodes = xml.getElementsByTagName('Prefix')
versions = [ checkValidVersion(n.firstChild.nodeValue) for n in versionNodes if n.firstChild ]
versions = [ v for v in versions if v is not None]
versions.sort(key=StrictVersion)
if len(versions) > 1:
latest = versions[-1]
print('downloading version %s'%latest)
r = requests.get('https://chromedriver.storage.googleapis.com/%s/chromedriver_win32.zip'%latest, stream=True)
with open('chromedriver.zip', 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
# simply call the unzip tool (must be available in path), using pythons zipfile package didn't work (incompatible format)
call(['unzip', 'chromedriver.zip'])
else:
print('no valid version found')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment