Jump to content
UBot Underground

Is it good coding practice to add allot of safegaurds


Recommended Posts

I'm fairly new to coding, around 4 months. I was wondering if its justified to add fail guards along the way as the bot runs through the code, just an example:

 

Say I want to log into a site, is it too much to add a safe guard that would check for successful log in and so forth with every major step after that.

 

thanks for sharing your wisdom
 

Link to post
Share on other sites

It is a good practice and I use it on all of my bots,since without that bot could get lost easily (especially when using proxies).

 

For example solving captcha is a good example of where you need to check for success, if you wouldn't, captcha could remain unsolved, bot stuck on that page, and the code bellow the success point wouldn't work because bot didn't reach the page for which it was coded for.

  • Like 1
Link to post
Share on other sites

I'm fairly new to coding, around 4 months. I was wondering if its justified to add fail guards along the way as the bot runs through the code, just an example:

 

Say I want to log into a site, is it too much to add a safe guard that would check for successful log in and so forth with every major step after that.

 

thanks for sharing your wisdom

 

 

This is something I need to learn to do as well. So far I haven't really put any safeguards for my bots... :P

Link to post
Share on other sites

It is a good practice and I use it on all of my bots,since without that bot could get lost easily (especially when using proxies).

 

For example solving captcha is a good example of where you need to check for success, if you wouldn't, captcha could remain unsolved, bot stuck on that page, and the code bellow the success point wouldn't work because bot didn't reach the page for which it was coded for.

What type of commands do you use for safeguarding? For example, if the captcha isn't detected as being successfully solved, what do you make the software do?

 

Restart again from a certain point? Or...

 

How in-depth to you make your safeguarding? :) Do you have success checks after every page? Or maybe less...

 

I'm thinking of safeguarding my software as well, but it takes more time doing that when creating bots so not sure how detailed the safeguarding should be...

Link to post
Share on other sites

What type of commands do you use for safeguarding? For example, if the captcha isn't detected as being successfully solved, what do you make the software do?

 

Restart again from a certain point? Or...

 

How in-depth to you make your safeguarding? :) Do you have success checks after every page? Or maybe less...

 

I'm thinking of safeguarding my software as well, but it takes more time doing that when creating bots so not sure how detailed the safeguarding should be...

You need a loop while and counter, which counts how many times we have failed (increment inside if->$exist).

 

Here is an example of captcha solving:

navigate("http://ubotstudio.com/playground/captcha-form", "Wait")
wait for element(<name="ctl00$ContentPlaceHolder1$Button1">, "", "Appear")
set(#PAGE Loading, $true, "Global")
set(#PAGE Count, 0, "Global")
loop while($both($comparison(#PAGE Count, "<", 5), #PAGE Loading)) {
    change attribute(<name="ctl00$ContentPlaceHolder1$captcha">, "value", $solve captcha(<src=w"/assets/captcha.jpg?id=*">))
    click(<name="ctl00$ContentPlaceHolder1$Button1">, "Left Click", "No")
    wait for browser event("Everything Loaded", "")
    if($exists(<(id="result" AND innertext="correct!")>)) {
        then {
            set(#PAGE Loading, $false, "Global")
        }
        else {
            increment(#PAGE Count)
        }
    }
}
if($exists(<name="ctl00$ContentPlaceHolder1$captcha">)) {
    then {
        alert("Couldn\'t solve captcha.")
        stop script
    }
    else {
    }
}

If bot can't reach success page you can notify user to solve captcha manually for example, or you can change a proxy and try again from beginning (if you are working on fully automated bot).

 

Well, you need to check all the time if you are on the right page with the bot, else it could do stupid things, so yes, safeguard is required on almost every step. I usually set goals, and if that goal is not reached bot retries from beginning.

 

Sure it takes more time, but at the end your bot will be more robust and won't be failing randomly.

  • Like 2
Link to post
Share on other sites

Thanks for enlightening us on this ubotdev, got a question about IFs, isnt the else part of it mostly redundant, I mean the bot is just going to do the same thing with both examples of code:

 

if($both($exists(<innertext="Somthing1">), $exists(<innertext="Somthing2">))) {

        then {
            alert("Tada!")
        }
        else {

            alert("Oops")

        }

 

 

OR

 

if($both($exists(<innertext="Somthing1">), $exists(<innertext="Somthing2">))) {
        then {
            alert("Tada!")

}

 

alert("Oops")

 

 

and then it would just continue with the next line if both requirements are not met, is there a point to leaving else in there?

Edited by daveconor
Link to post
Share on other sites

Thanks for enlightening us on this ubotdev, got a question about IFs, isnt the else part of it mostly redundant, I mean the bot is just going to do the same thing with both examples of code:

 

if($both($exists(<innertext="Somthing1">), $exists(<innertext="Somthing2">))) {

        then {

            alert("Tada!")

        }

        else {

            alert("Oops")

        }

 

 

OR

 

if($both($exists(<innertext="Somthing1">), $exists(<innertext="Somthing2">))) {

        then {

            alert("Tada!")

}

 

alert("Oops")

 

 

and then it would just continue with the next line if both requirements are not met, is there a point to leaving else in there?

Else part of if statement is redundant in some cases, but in your code examples it's not, since it produces different behavior. 1st code would only and always display only one alert (one or another message), while 2nd part would display two alerts if both elements exist on the page).

 

In my code you could remove last "else" without any consequences, since it is empty.

Link to post
Share on other sites

Thanks UBotDev for the awesome insight! :) This will help me a lot in improving my bot.

 

I'll go back and add some safeguards in later...

 

It's troublesome without safeguards. At the moment, I keep monitoring my bot to see how it's doing because I'm worried it'll fail somewhere in the middle and I won't know what went wrong. LOL. :P

 

Thinking also of adding a monitor bar with increments. Like for every step, it increments progress by 10 or 20% maybe in a UI stat bar, so I can see it's how many percent complete the project is. If it fails in the middle, I'll know where the problem is roughly...

Link to post
Share on other sites

How do you report back to DeathByCaptcha if the answer is wrong?

They claim they will only charge you for successful ones, but the software needs to support telling their API it failed.

Anyone know how to tell them it was solved bad?

Link to post
Share on other sites

Should have seen it coming, Doh :)

 

But still I wanted to know if else could be removed when not needed which you answered yes, thanks.

No problem. Yep, exactlly, you can remove it instead of leaving it empty.

 

Thanks UBotDev for the awesome insight! :) This will help me a lot in improving my bot.

 

I'll go back and add some safeguards in later...

 

It's troublesome without safeguards. At the moment, I keep monitoring my bot to see how it's doing because I'm worried it'll fail somewhere in the middle and I won't know what went wrong. LOL. :P

 

Thinking also of adding a monitor bar with increments. Like for every step, it increments progress by 10 or 20% maybe in a UI stat bar, so I can see it's how many percent complete the project is. If it fails in the middle, I'll know where the problem is roughly...

No problem, you owe me a pizza, because your avatar made me hungry. :)

 

It is time consuming to add the safeguards, that's why you need to pick the right places and don't over do it....although on the other side the more you have the more robust the bot will be.

 

Adding such protection won't only make your bot more robust (making sure it's always on the right page), if you add alerts it will also tell you where exactly bot got stuck. Beside that this would also detect any potential changes in the HTML of the site (like when site gets a new template).

  • Like 1
Link to post
Share on other sites

No problem. Yep, exactlly, you can remove it instead of leaving it empty.

 

No problem, you owe me a pizza, because your avatar made me hungry. :)

 

It is time consuming to add the safeguards, that's why you need to pick the right places and don't over do it....although on the other side the more you have the more robust the bot will be.

 

Adding such protection won't only make your bot more robust (making sure it's always on the right page), if you add alerts it will also tell you where exactly bot got stuck. Beside that this would also detect any potential changes in the HTML of the site (like when site gets a new template).

 

LOL. Sure. :)

 

Thanks a lot. I will keep that in mind...

Link to post
Share on other sites

OK. So I've been trying to build safeguards using the loop while function, but my mind is getting messed up. Lol. :) 

 

It works well, but I don't really like the round about thinking, and all the conditions I need to add each time.

 

I was wondering if I could create safeguards using if-then nodes instead, like this for example...

 

1. Define a command to fill in a form

 

2. Call on the defined command, and fill in the form

 

3. Use an if-then statement:

      - Check if the form is filled

      - If form not filled, then run the defined command again to fill it

 

4. Use an if-then statement:

     - Check if the form is filled again

     - If form not filled, then alert and stop script

Link to post
Share on other sites

There are different levels of safeguards you can put into your code.

 

You have the simple one where you check if a page contains a certain piece of text, and if it does then continue, else, reload page/wait/etc

 

you can then have a set command that tracks if a function/command has finished, and if it has then set true, and then the next function is not called unless the last function is set to true, otherwise breakout and start the loop again.

 

the best way is passing a parameter based on true false into a command that is working with another command, and then that way each of your commands, if they have completed properly, are telling the next command, "i have done my job correctly" This means that if they haven't done their job correctly that they just loop back around, and start again, retry the last command, or wait (whatever you want)

 

This is where thinking about your code separately from the functions to the functionality comes into play.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...