bhat 0 Posted May 18, 2017 Report Share Posted May 18, 2017 Can someone tell me how I can make my "loop while" loop only for a certain number of times. I set ubot to click through "next" until it finds a link/listing to click on. But I want it to end the loop after about 20 "next" clicks and not let the loop go on forever (if the link is not found then I want ubot to restart again or go to the end through the rest of the ubot code where it is set to automatically restart via another loop code). Here is the code I have now for the "loop while" command: loop while($not($exists(<innertext="THE LINK TEXT IS INSERTED HERE">))) { wait for browser event("Everything Loaded", "") wait(1) then { run javascript("window.scrollTo(0,document.body.scrollHeight); ") focus(<id="pagnNextString">) mouse over(<id="pagnNextString">, "No") click(<id="pagnNextString">, "Left Click", "No") wait for browser event("Everything Loaded", "") wait(1) } wait for browser event("Everything Loaded", "") wait(1) } wait($rand(1, 4)) focus(<title="THE LINK TEXT IS INSERTED HERE">) mouse over(<data-attribute="THE LINK TEXT IS INSERTED HERE">, "No") click(<data-attribute="THE LINK TEXT IS INSERTED HERE">, "Left Click", "No") wait for browser event("Everything Loaded", "") Also my second question is how do I avoid clicking on the advertisement links with the same link name? I only want to be clicking on the non-advertisement, non-paid links. Thanks in advance for your help, Bhat Quote Link to post Share on other sites
Varo 28 Posted May 19, 2017 Report Share Posted May 19, 2017 You can set variable to count your loop before loopwhile begin.Then use 'both' function in loopwhile, and then put increment in the end of loopwhile.See code below set(#countloop,0,"Global") loop while($both($not($exists(<innertext="THE LINK TEXT IS INSERTED HERE">)),$comparison(#countloop,"<= Less than or equal to",#put_your_maximum_loop_here))) { wait for browser event("Everything Loaded","") wait(1) then { run javascript("window.scrollTo(0,document.body.scrollHeight); ") focus(<id="pagnNextString">) mouse over(<id="pagnNextString">,"No") click(<id="pagnNextString">,"Left Click","No") wait for browser event("Everything Loaded","") wait(1) wait($rand(1,4)) focus(<title="THE LINK TEXT IS INSERTED HERE">) mouse over(<data-attribute="THE LINK TEXT IS INSERTED HERE">,"No") click(<data-attribute="THE LINK TEXT IS INSERTED HERE">,"Left Click","No") } increment(#countloop) } 3 Quote Link to post Share on other sites
bhat 0 Posted May 19, 2017 Author Report Share Posted May 19, 2017 (edited) Hi Varo, thanks I'm going to try this now. One more thing I encountered is that there is sometimes a captcha page that comes on. Is there any tips to restart the ubot code if I encounter a captcha page during this loop? Maybe a code that says if the page is the-captcha-page-url.com then stop script and start entire ubot script from the beginning? Edited May 19, 2017 by bhat Quote Link to post Share on other sites
Varo 28 Posted May 19, 2017 Report Share Posted May 19, 2017 Hi Varo, thanks I'm going to try this now. One more thing I encountered is that there is sometimes a captcha page that comes on. Is there any tips to restart the ubot code if I encounter a captcha page during this loop? Maybe a code that says if the page is the-captcha-page-url.com then stop script and start entire ubot script from the beginning? do you mean you have three "condition to wait for" : 1. not contain link text2. less than or equal your maximum loop set3. not containing captcha page. If so, it can be done. Just change one of your condition to "both" and then put your another two condition. 1 Quote Link to post Share on other sites
bhat 0 Posted May 19, 2017 Author Report Share Posted May 19, 2017 (edited) Hi Varo, the code worked for stopping the loop, thanks again. Yes, but I am not sure how to make the three conditions. Can you show me an example to add the third condition of not containing captcha page? Also, is there a way that if either one of the 3 conditions are true (1. not contain link text 2. less than or equal your maximum loop set 3. not containing captcha page) then I stop the script code and immediately restart it from the beginning? What I have now is that it stops the loop set but proceeds with the rest of the script code actions. PS: I'm not sure if the captcha page url may change. Maybe it's better to make the variable that it contains the captcha page text "Type the characters you see in this image:" Edited May 19, 2017 by bhat Quote Link to post Share on other sites
Varo 28 Posted May 19, 2017 Report Share Posted May 19, 2017 Hi Varo, the code worked for stopping the loop, thanks again. Yes, but I am not sure how to make the three conditions. Can you show me an example to add the third condition of not containing captcha page? Also, is there a way that if either one of the 3 conditions are true (1. not contain link text 2. less than or equal your maximum loop set 3. not containing captcha page) then I stop the script code and immediately restart it from the beginning? What I have now is that it stops the loop set but proceeds with the rest of the script code actions. PS: I'm not sure if the captcha page url may change. Maybe it's better to make the variable that it contains the captcha page text "Type the characters you see in this image:" This is loop while with three condition: set(#countloop,0,"Global") loop while($both($both($not($exists(<innertext="THE LINK TEXT IS INSERTED HERE">)),$not($exists(<innertext="Captcha Page">))),$comparison(#countloop,"<= Less than or equal to",#put_your_maximum_loop_here))) { wait for browser event("Everything Loaded","") wait(1) then { run javascript("window.scrollTo(0,document.body.scrollHeight); ") focus(<id="pagnNextString">) mouse over(<id="pagnNextString">,"No") click(<id="pagnNextString">,"Left Click","No") wait for browser event("Everything Loaded","") wait(1) wait($rand(1,4)) focus(<title="THE LINK TEXT IS INSERTED HERE">) mouse over(<data-attribute="THE LINK TEXT IS INSERTED HERE">,"No") click(<data-attribute="THE LINK TEXT IS INSERTED HERE">,"Left Click","No") } increment(#countloop) } And about restart it from beginning i am not sure. But you can try it. Use define command. 1 Quote Link to post Share on other sites
bhat 0 Posted May 19, 2017 Author Report Share Posted May 19, 2017 Thanks Varo! I'm not sure about restart also, but I will just let it run through the entire script for now instead of restart. Your help with stopping that loop with the three conditions really helped me a lot. Thank you! Quote Link to post Share on other sites
Varo 28 Posted May 20, 2017 Report Share Posted May 20, 2017 Thanks Varo! I'm not sure about restart also, but I will just let it run through the entire script for now instead of restart. Your help with stopping that loop with the three conditions really helped me a lot. Thank you!I am glad to help. 1 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.