Simple AHK_L Browser Bot

Discussion in 'Web Development and Programming' started by Cerberus, Oct 18, 2013.

  1. Cerberus

    Cerberus Admin Talk Staff

    Joined:
    May 3, 2009
    Messages:
    1,031
    Likes Received:
    500
    So, a lot of people have been asking me about bots and such as of late. I figured I would show how easy and quickly a bot can be made. This bot honestly took me about 2 mins to make. It clears IE to remove all cookies and such, then navigates to this site, and then logs in. It also saves your username and password to an ini file on your computer. I like doing this for most bots because I am lazy, and it is the best method in my opinion.

    I have included a compiled version in the Zip along with the source code. In order to run it straight from source you need to have AHK_L installed. But, everything is there :) As you can see, there is not much to it, and it is very efficient as far as a coding language when it comes to automation. And yes I have been and will always be a HUGE FANBOY for AHK :)

    Source Code of Bot Commented:
    Code:
    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    ; #Warn  ; Enable warnings to assist with detecting common errors.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
    
    
    GoSub, Settings
    GoSub, Bot
    Return
    
    Settings:
    ;============== This code checks for AT.ini if not there asks for info
    IfExist, AT.ini
    {
      IniRead, User, AT.ini, Settings, User, %A_Space%
      IniRead, Pass, AT.ini, Settings, Pass, %A_Space%
    }
    
    IfnotExist, AT.ini
    {
      InputBox, User, AT, Enter your AT username.
      InputBox, Pass, AT, Enter your AT password.
      IniWrite, %User%, AT.ini, Settings, User
      IniWrite, %Pass%, AT.ini, Settings, Pass
    }
    Return
    
    Bot:
    ;==============
    Process, Close, iexplore.exe ; Closes IE
    RunWait, RunDll32.exe InetCpl.cpl`,ClearMyTracksByProcess 2,, Hide ;clears cookies
    Pwb :=  ComObjCreate("InternetExplorer.Application")  ; Hooks into IE
    Pwb.Visible:=True ; True means you can see false you hide window
    Pwb.Navigate("http://admin-talk.com/") ; url you want to go to
    LoadPage(Pwb) ; funtion to check if page is loaded
    
    
    ;============== javascript used to access and imput field many ways by index, id so on etc clicks login to pull down form
    Pwb.document.getElementsByTagName("A")[0].click()
    ;============== Sleeps for half a second
    
    Sleep, 500
    ;============== javascript used to access and imput field many ways by index, id so on etc enter info into form and clicks login
    Pwb.document.getElementsByTagName("input")[0].value := User
    Pwb.document.getElementsByTagName("input")[3].value := Pass
    Pwb.document.getElementsByTagName("input")[4].click()
    LoadPage(Pwb)
    
    ;============== Reads the page into Variable
    Page := pwb.document.body.innerHTML
    
    ;============== Checks the page for Inbox
    Ifinstring, page, Inbox
    {
    Msgbox You are now Logged In!
    ExitApp ; Exits the program
    }
    Else
    {
    Msgbox Something went wrong!
    ExitApp ; Exits the program
    }
    
    LoadPage(Pwb){
    While pwb.readyState!=4 || pwb.document.readyState!="complete" || pwb.busy ; Waits for page to load
      Sleep 1000
    }
     

    Attached Files:

    eva2000 and Brandon like this.
  2. MyDigitalpoint

    MyDigitalpoint Regular Member

    Joined:
    Jun 5, 2013
    Messages:
    114
    Likes Received:
    30
    Location:
    Virtual World
    WOW! Looks easy and though I never considered to make my own bot.

    Nonetheless I will have to give this coding a go, that's for sure.

    Hmm... not that sure what I need it for though :evillaugh:
     

Share This Page