1:52
3:12
Loops allow you to build more dynamic content workflows. They can be applied on a given function in your logic to have it iterate over a list of values.
To best explain how this functionality works, we will be taking the following app as an example.
Here we have a workflow consisting of two functions, a SERPs search followed by a Scrape Webpage. Our goal here is to get the top 10 SERPs then apply a loop on the scraping function to fetch the contents of all 10 results.
1. To add apply the loop, click on the "plus" button right under the node ID.
2. In the configuration, you will need to provide an "Iterator" this is the list of values that we want to loop this function over. This will be our SERPs so will reference that here and click on setup loop. when the Skip Failed checkbox is ticked, if any of the pages fail to be scrapped then they will be ignored, otherwise the whole workflow would fail and return an error.
3. Now if we type in a slash '/' in the URL field you'll see we have a new reference value called {{item}}
. This represents the value in the list that we're looping over.
If we go back to the SERP Search function and hover over the info icon we can see exactly what it outputs:
Since we want to scrape the SERPs result page content, we want to pass the link of the item to the URL field in the Scrape Webpage function, so we will reference that using dot notion like so {{item.link}}
.
Now this will return a list of all the page's contents for a given SERP. We can pass these to a Chat Model for analysis, or even use it as an iterator for the proceeding step to analyse each page separately. Here's what we get when we run this app and display the results in a table.
For a great example on how looping can be used to build powerful content workflows, check out our listicle writer app here, you can clone it and see what's happening behind the scenes.