Search Wiki

Tutorial – Bulk Download Your Deep Dreams (Advanced)

NOTICE:

1. The source code for this project can be downloaded here.

2. A simple version of this tutorial, for Windows users only, can be found here.

What this tutorial will cover:

  1. Who is this tutorial for?
  2. Installation
  3. Create Project
  4. Add packages to SDK
  5. Setting up ChromeDriver
  6. Setting up Source Code
  7. Running Project
  8. Additional Resources

[1] Who is this tutorial for?

This tutorial is for you only if:

  1. You have many DDG images you want to download in bulk, automatically.
  2. You are familiar with code, and preferably, wanted to learn to code regardless of DDG.
  3. You see yourself doing more development after this project is done.

[2] Intellij Installation

I recommend the Intellij CE + Python Plugin, since Intellij CE is free and supports multiple languages, and the other alternative, installing PyCharm, provides no additional functionality. So basically you get multi-language for free by choosing Intellij CE + the Python Plugin.

Intellij CE installation (for Windows): Follow this link, and choose the option ‘Community’.

For Mac: Follow this link, and choose the option ‘Community’.

After installation, you will see the following window after opening Intellij:

Image1

You can ignore the existing projects, since you will start with no existing projects.

To add the Python Plugin:

  1. Click on ‘Configure’ at the lower right corner.
  2. Choose option ‘Plugins’. A new Plugins window will open.
  3. In the upper left corner, type in ‘Python’.
  4. Install the Python Plugin.

Image2

Python SDK: Conda offers many tools for Python 3 development and has a built in Python SDK. It is also free. If disk space is not an issue for you, I recommend downloading Conda and using it’s SDK.

Conda’s functionality will not be clear for this project, but if you continue using Python 3, it will help you a great deal.

Installing Conda (For Windows): Follow this link.

For Mac: Follow this link.

Now you are set to start a new Python Project.

[3] Create Project

Return to the Welcome Window, and this time click on ‘Create New Project’. A new window ‘New Project’ will open. In the left list of project types, select ‘Python’.

It should look similar to this (Except you will not have a Project SDK selected! We will get to that next):

New project

Now you will need to setup the Python SDK from Anaconda for the project. Next to ‘Project SDK: ‘ you will see in the top right corner, a button ‘NEW…’. Click the button.

You will now see a window that looks similar to this (but with not Environment configured yet):

Sdk

 

Now select ‘Virtualenv Environment’ in the left option list, and click on ‘New environment’. Next to ‘Base interpreter’ you will need to give the path to the python interpreter of Anaconda, that you downloaded. In windows, the path should be similar to: ‘C:\Users\<USER>\Anaconda3\python.exe’.

Now click OK, then ‘NEXT’, then ‘NEXT’ again. For consistency, we will name our project ‘BulkDownloader’. Also set ‘Project location’ to a location of your choice, but just be sure the location path ends with ‘BulkDownloader’ as well. Do not update the ‘More Settings’ at the bottom, they auto-update to the correct values.

It should look like this:

Project naming

 

now click ‘FINISH’ and wait a bit for the IDE to load the new project.

[4] Add Packages to SDK

In the top bar, under File, you will find the ‘Project Structure’. Click on it, then choose SDKs.

Image5

After the SDK is added, go to ‘Packages’, and add the following libraries to the SDK (from + sign):

‘selenium’, ‘urllib ‘ and ‘unittest’.

Image6

[5] Setting up ChromeDriver

Windows:
You will see attached to this tutorial a file chromedriver.exe, put the file in a permanent location, be sure that the path to it does not include spaces or special characters and then change the path to your location (instead of ‘C:’). NOTICE: For some machines, only the latest version of ChromeDriver.exe work. So you might want to download the file yourself from here.
Mac / Linux: 

You will need to download the latest chromedriver file from here. After you download the file, put the file in a permanent location, be sure that the path to it does not include spaces or special characters and then change the path to your location.

[6] Setting up Source Code

You will see attached to this tutorial the source code for the project. This is the actual code that runs the program. After you unzip the downloaded file, open ‘BulkDownloadProject’ folder, and open all Python (.py) files with your editor of choice.

Now create under your own project ‘BulkDownloader’, new Python files using rightclick on the project name. Name the files exactly the same as the Python files in the unzipped

‘BulkDownloadProject’ folder, and copy the content of the unzipped project files into the files with the same names, you just created.

 

[7] Running Project

Finally, you will need a new ‘Run Configuration’.

In top bar, under ‘Run’, you will see the ‘Edit configurations’ option. Create a new Python tests > UnitTest configuration and give it the path to the run.py file.

 

[8] Additional Resources

Python refresher

There are many great tutorials out there for Python. I recommend this Udemy Course in particular.

 

The Selenium Library

You will notice I use Selenium (Together with PyTest and UnitTest) for these tests. In short, Selenium is a library that allows you to mimic user actions, as well as get elements from the DOM. The most important object to know about is the ‘driver’, which can be thought as a real driver, navigating web pages, searching for specified elements and clicking them, setting values, etc.

Please go over this documentation for more information. There is also a Udemy course for this that is quite basic.

1 comment on Tutorial – Bulk Download Your Deep Dreams (Advanced)

Leave a Reply