daveconor 1 Posted August 23, 2013 Report Share Posted August 23, 2013 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 Quote Link to post Share on other sites
UBotDev 276 Posted August 23, 2013 Report Share Posted August 23, 2013 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. 1 Quote Link to post Share on other sites
daveconor 1 Posted August 23, 2013 Author Report Share Posted August 23, 2013 thanks for the reply UbotDev Quote Link to post Share on other sites
Pizza Pro 11 Posted August 23, 2013 Report Share Posted August 23, 2013 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... Quote Link to post Share on other sites
Pizza Pro 11 Posted August 23, 2013 Report Share Posted August 23, 2013 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... Quote Link to post Share on other sites
Aymen 385 Posted August 23, 2013 Report Share Posted August 23, 2013 use if with an exists function , to check if a certain string exists on a webapge Quote Link to post Share on other sites
UBotDev 276 Posted August 23, 2013 Report Share Posted August 23, 2013 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. 2 Quote Link to post Share on other sites
positivity13 4 Posted August 23, 2013 Report Share Posted August 23, 2013 Thanks guys this couldn't have come at a better time. Must have read my mind. Quote Link to post Share on other sites
daveconor 1 Posted August 23, 2013 Author Report Share Posted August 23, 2013 (edited) 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 August 23, 2013 by daveconor Quote Link to post Share on other sites
UBotDev 276 Posted August 23, 2013 Report Share Posted August 23, 2013 Sorry, I wanted to edit previous post but I created a new one bellow by accident. Quote Link to post Share on other sites
UBotDev 276 Posted August 23, 2013 Report Share Posted August 23, 2013 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. Quote Link to post Share on other sites
daveconor 1 Posted August 23, 2013 Author Report Share Posted August 23, 2013 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. Quote Link to post Share on other sites
Pizza Pro 11 Posted August 23, 2013 Report Share Posted August 23, 2013 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. 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... Quote Link to post Share on other sites
Denethor 1 Posted August 23, 2013 Report Share Posted August 23, 2013 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? Quote Link to post Share on other sites
UBotDev 276 Posted August 24, 2013 Report Share Posted August 24, 2013 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. 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). 1 Quote Link to post Share on other sites
Pizza Pro 11 Posted August 24, 2013 Report Share Posted August 24, 2013 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... Quote Link to post Share on other sites
the_way 52 Posted August 25, 2013 Report Share Posted August 25, 2013 i build every function with an error checking function attached to it. No question. Quote Link to post Share on other sites
Pizza Pro 11 Posted August 27, 2013 Report Share Posted August 27, 2013 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 Quote Link to post Share on other sites
the_way 52 Posted August 29, 2013 Report Share Posted August 29, 2013 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.