Python Automation

Introduction to BotCity’s Web Bots

Follow this article or the video below to learn how to use Botcity’s Web Bot:

Prerequisites:

Step 1 – Use CookieCutter to start a new project

Creating a Web Bot is very similar to creating a Desktop Bot. Let’s start by using the same CookieCutter command we used to install the Desktop version: “python -m cookiecutter https://github.com/botcity-dev/bot-python-template”.

You’ll be prompted for the following information:

  • project_type: Make sure to pick “Web”.
  • bot_id: This will be the name of your Python module. If you’re using the BotMaestro integration, then it must match the bot label configured on BotMaestro.
  • project_name: This is the name of the project. You can pick any name you would like.
  • project_short_description: This is a short description of the bot.

Notice how the Web bot has the same project structure as the Desktop version:

Step 2 – Configuring the WebDriver

The Web bot uses the WebDriver engine to provide a very fast and reliable web navigation. In order to use it, you can either have the WebDriver installed on your PATH variable, or provide your automation a path to the WebDriver’s executable. Either way, you must first download it and store it in whatever folder your prefer:

Then, go to your bot’s source code and add this line to it:

Step 3 – Playing with the Source Code

Let’s make things a bit more interesting by changing the default automation a little bit, okay? We’ll make the bot open the BotCity’s youtube channel and extract the current number of subscribers, but feel free to design your own first web bot!

Step 4 – Run the bot template

We’ll use the build.bat executable provided in the template to quickly compile our bot, but you could use the terminal to do it as well, like we did for the Desktop bot in our previous article. Then, we’ll run our bot with “python -m firstWebBot”, and verify that it opens Botcity’s Youtube Channel and extracts the correct number of subscribers:

Now, let’s run this automation again, but with the self.headless variable set to true:

Now you won’t see the bot opening the BotCity’s youtube channel page, or even the browser. Everything will be done in the background, but you can confirm that it’s still working by checking out the bot’s output on the console:

Head of Developer Experience @ BotCity.

Leave a Reply

%d bloggers like this: