Jump to content
UBot Underground

"loop While" For A Certain Number Of Times?


Recommended Posts

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

Link to post
Share on other sites

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)
}

  • Like 3
Link to post
Share on other sites

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 by bhat
Link to post
Share on other sites

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 text

2. less than or equal your maximum loop set

3. 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. 

  • Like 1
Link to post
Share on other sites

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 by bhat
Link to post
Share on other sites

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. 

  • Like 1
Link to post
Share on other sites

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!

Link to post
Share on other sites

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. :) 

  • Like 1
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...