While loop in a while loop

I have a loop that scrapes prices from a website.
Each page has 100 products and the website where im scraping has 6000 pages.

so I created a while loop that clicks on the next page till <= 6000.
Inside that while loop I have another while loop that scrapes till <= 100 products.

The problem is that after it scrapes the 100 products it goes to the bigeer loop, and just loops there in the outer loop changing pages till it reaches 6.000.
It never runs the inner loop again .

The idea would be for it to go to next page and then beagin again the inner loop that scrapes prodcuts till 100 before going to the outer loop and changin page once again.

I Believe it may be beacuse the inner loop already acomplished its condition, but how can i make it restart? (May be the problem is not there)

I dont want to use wizard.

Why not? This is literally what Table Extraction is meant for, and it works great. You’d be done already.

beacuse the wizard dosent get the 100 products it always cuts in between.

Hi

There are a few ways to make your UiPath loop restart the inner loop after it finishes scraping the 100 products.

One way is to use a Do While loop instead of a While loop for the outer loop. A Do While loop will always execute the loop body at least once, even if the condition is not met. This means that the inner loop will always be executed at least once, even if it finishes scraping the 100 products before the outer loop condition is met.

Another way to make the loop restart the inner loop is to use a Sequence activity inside the outer loop. The Sequence activity will execute all of the activities inside of it in order. This means that you can put the inner loop inside of the Sequence activity and the Sequence activity will restart the inner loop after it finishes executing.

Here is an example of a UiPath workflow that uses a Do While loop to restart the inner loop:

* Do While
    * Get the next page of products from the website
    * For each product on the page
        * Scrape the product price
    * End For
* End Do While

An example that uses a Sequence activity to restart the inner loop:

* Sequence
    * Get the next page of products from the website
    * For each product on the page
        * Scrape the product price
    * End For
* End Sequence

Which method you choose will depend on your specific needs and preferences. If you need to ensure that the inner loop is always executed at least once, then you should use a Do While loop. If you need more flexibility, then you can use a Sequence activity.

Hope this helps

Cheers @Favarelaa

The reason it cuts in between is the page may be not loaded fully.
The page might show products only if you scroll down.
Try to scroll the page till the end (you need to have some logic how many scrolls does loads 100 products) and then scrape the structured data.
This way you can scrap 100 products without any issues.

Regards,
Kartheek Byggari

Then figure out why that is, you must not have it configured correctly.

Anyway, the condition for your outside loop should be that the “next” button still exists. Is that what you have?

So what you say makes perfect sence to me, but I tried it and still get the same outcome.

The While Activity, it does it perfectly in the first 101 elemnts I ask for, but after that, the automatation goes out of that while and only loops with the scroll mouse activity, the click activity and the assign activity.

It never goes back in to the first while activity again.
Can you help me?

Inside the inner while loop make sure the lisiting index value is incremented @Favarelaa

You are right. It Does have an incrementer, but at the end of my sequence I need to restart it with listingIndex = 1, because on the second page the index dosent start at 102 it starts at 1 once again.

I fixed it, thank you for all your help.
I learned a lot!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.