cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
donaldekpe
Helper II
Helper II

How do I extract only the first few items in a list

Hello,

I am trying to use the 'Extract data from webpage' action to extract just the first few items from a list of span elements on a webpage. Every time I select up to the second item, it automatically selects all the items for extraction. I do not need all the items, just the first 10 items. How do I go about this, please?

 

1 ACCEPTED SOLUTION

Accepted Solutions

At first saw it on the forum itself 😊 and then found it here 

 

https://learn.microsoft.com/en-us/power-automate/desktop-flows/variable-data-types

VJR_0-1664766008562.png

 

 

View solution in original post

11 REPLIES 11
lbendlin
Impactful Individual
Impactful Individual

Add a loop counter variable to your flow.  Exit the loop at the appropriate moment.

VJR
Super User
Super User

Hi @donaldekpe 

 

Every time I select up to the second item, it automatically selects all the items for extraction

This is by design that PAD automatically detects and gives us a table based on the first two selections.

 

Here are some options for what you are trying to do.

1. Extract just the first item. See its html in the Advanced Settings and likewise get the second item. 

Eg;

/..../Div(0)/Input(0) -> if this gives the first item

/..../Div(0)/Input(1) -> then get the second item separately 

 

Either use a separate Extract data from webpage or use the Handpicked values option of the Extract data from webpage to extract both at once

 

VJR_0-1664163450084.png

 

 

2. If you are having trouble with that then to get the first few items of a list below is the syntax

If MyList is your list then use %MyList[0:2]% to get the first two items.

 

 

Thank you for the response. How do I do this though. Do I add the extract action into the the loop and then select the first item to be extracted while the loop extracts the rest?

donaldekpe
Helper II
Helper II

Thank you for the reply. I have tried using the handpicked option but I noticed it only extracts the values into just one row rather than in one column like a list would look like. I want to loop through the values extracted and so having everything in just one row would make it look like a single value only. I hope you get me.

 

You wrote something about a syntax. I believe that could help but how do I use that syntax, where do I put it, is it javascript? Sorry, I am a bit of a noob here, but I learn fast.

For the syntax part of the answer:

 

Do what you were originally doing ie; 

"'Extract data from webpage' action ....Every time I select up to the second item, it automatically selects all the items for extraction"

When you run this action in PAD it will give you the result in a datatable.

Then you can use a For each loop on the datatable and just get the top required rows. ie; If you need top 3 items then exit the loop after 3 iterations of the loop.

donaldekpe
Helper II
Helper II

Ok, I get that. I actually want to continually loop through the first ten items without exiting, at least not until the flow itself is stopped.. Is there a way to do this?

- Have a Counter variable set to 10

- Within the loop have a If condition to check if the value of Counter is greater than 10. If yes, use Exit Loop.

- Just before the loop end, increment the counter by 1

donaldekpe
Helper II
Helper II

Thank you for the help. I will give that a try.

I remember seeing this syntax a long while back. Where did you discover it? 😅

At first saw it on the forum itself 😊 and then found it here 

 

https://learn.microsoft.com/en-us/power-automate/desktop-flows/variable-data-types

VJR_0-1664766008562.png

 

 

wow! Thank you so much for this, it worked well. Exactly what I have been looking for.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Top Kudoed Authors
Users online (2,127)