[python]Download geckodriver for windows

I am writing a python script that uses requests module to download the latest release of geckodriver.exe for windows 64-bit, I added a few functions to make the download slightly more dynamic by identifying the OS type and the system architecture, and after downloaded unzip the package into the defined path I specified.

The current script only downloads geckodriver for windows, this is a precursor for my future work to include downloads for machintosh and linux, hence the OS type function still identifies linux and mac other than windows.

The following is the breakdown of what the functions do:

  • init_log – Initializes the logger, instead of using print function to track what the script is doing logger is used. The logs are displayed on stderr to highlight the progress of the script.
  • os_architecture – Identifies whether the system is 32 or 64-bit and returns a string.
  • os_type – Identifies the OS used for the system.
  • get_latest_dl_link – Gets the download link of the latest geckodriver for windows.
  • download_gecko_for_win – Downloads the geckodriver package.
  • unpack – Decompress/unzip the package downloaded.

The code in its entirety can be found here.


Scenario 1: Geckodriver is not found in system.

The series of log describing what the script is doing.
The directories created, success.png is the screenshot taken by selenium.
The zip package downloaded from github.
The extracted geckodriver.exe
The screenshot taken by selenium which is success.png

Scenario 2: Geckodriver.exe exists

No download as geckodriver.exe is available, the screenshot is taken.
See the Date modified, the success.png is saved at 11.34pm which matches the log.

Scenario 3: geckodriver.exe put to recycle bin

Anything in recycle bin if not empty or not securely deleted is not actually deleted, the file is still in the Windows.

As shown in the log the geckodriver.exe was fetched from recycle bin, and still works.
See the date modified, the time matches the log.


One thought on “[python]Download geckodriver for windows

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s