Bots. How programing them can help you or your company?

in #programming7 years ago

First of all, what is bot?
webbot_2x.jpg
(Wikipedia) An Internet bot, also known as web robot, WWW robot or simply bot, is a software application that runs automated tasks (scripts) over the Internet. Typically, bots perform tasks that are both simple and structurally repetitive, at a much higher rate than would be possible for a human alone.
Today Im going to show you how to make simple bot, which will log you into facebook.

First of all, what program should we use???
coding-language-for-dynamic-webdevelopment.jpg
Well, there is a plenty of posibilities. Few years ago (when i was 19) I was working in an Insurance Agency and i was responsible for sending policies farther to other agencies. Before sending them i had to check them out in online data base. I hated that. It was the worst part. Data base site was working so bad and loading so long, that every single click was cousing 10-15 second waiting and loading. Now imagine checking like 200 or 300 boxes and fill same amount of text fields. It was taking HOURS...
So i thought What if bot would do that for me?. I started searching...

AutoIt

Of course I could do that in every single programming language, but when I saw AutoIt custom made libraries, I knew that was thing I was looking for. Specially library made for Internet explorer or Chrome. It couldnt be more simple to make my bot than with this program.

Downloading and Installing
Just go to AutoIt site, download it and install it. Its as simple as that.
When Installator asks you what you want .au3 files to do you choose run, not edit.
Now when you will just click on script on your desktop it will just run.
Installation cointains SciTE Script Editor for editing scripts.

How to start?
First of all lets see library. Its called _IE.au3(very innovative name, au3 is extension).
2.png
https://www.autoitscript.com/autoit3/docs/libfunctions/IE%20Management.htm

Lets see what do we need... We want our script to:
1 start new IE window
2 lounch www.facebook.com
3 fill email field
4 fill pass field
5 click login button
So for sure _IECREATE(create IE window), _IELoadWait(waits for IE to fully load website), _IEGetObjById(get reference to objects like buttons and text fields) and _IEAction(provides action on objects)

Scripting
Before we start scripting we need to know the ID of objects we want to use. To do that we go to fb login page(you guys can see me and my girlfriend, she will not be happy if she will see her face here :P) and right click on the email text field and select inspect element and look at id field. We can see input id="email", thats what we are looking for. We could also use _IEGetObjByName function, but id's are usually shorter and more intuitive. Do the same thing with password and login button. Write those id's somewhere or try to remember them. Or maybe just write them down to be sure ;)
33.png
44.png

We start with
#include <IE.au3>
we just included library

Now
Local $ieWindow =_IECreate ("www.facebook.com",1)
_IELoadWait ($ieWindow )
we just lounched fb url and made reference to it - ieWindow
and we are waiting for IE to load our url from ieWindow

So we got our fb login site and our empty text fields and login button
now we have to take our id's list and take email field id which is email
Local $mail = _IEGetObjById($ieWindow , "email")
_IEFormElementSetValue($mail, "bla")
first line will make variable mail wich will store treference to email field in ieWindow which is got by _IEGetObjById function and second line will fill mail with string bla(in bla you put your email address)

Same thing with password
Local $pas = _IEGetObjById($o, "pass")
_IEFormElementSetValue($pas, "123456789")

And of course clicking login button with
Local $log_but = _IEGetObjById($o, "loginbutton")
_IEAction($log_but,"click")

55.png

So yeah, thats pretty it.
9 lines and you can login to facebook with just 2 clicks on your desktop.

Summary
Script i made for that company was a little bit more complex. Before filling data base it was taking policies numbers from txt file and do some more things. You can do anything from working on excel files to making steam trading bots. Whatever you want.

If you liked it and want me to do something more with autoit give a follow and upvote to let me know. ![autoit.png]