# HTTP / HTML extract loop problem

**URL:** <https://community.n8n.io/t/http-html-extract-loop-problem/10562>\
**Category:** Questions\
**Tags:** core\
**Created:** [January 12, 2022, 12:08pm UTC](https://community.n8n.io/t/http-html-extract-loop-problem/10562 "2022-01-12T12:08:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_sabo](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/martin_sabo/32/9723_2.png) [@martin\_sabo](https://community.n8n.io/u/martin_sabo)\
**Post date:** [January 12, 2022, 12:08pm UTC](https://community.n8n.io/t/http-html-extract-loop-problem/10562/1 "2022-01-12T12:08:53Z")

</div>

Hello community.  
Im doing parser with loop.  
The workflow is like this:

- **HTTP Request** - starting URL [domain.com/startUrl](http://domain.com/startUrl)
- **HTML Extract** - in this step im extracting URL of json file (/something/ID/something.json)  
— (something.json has dozens of pages, on each page/json file are 0-5 links to profiles (some profiles are private so doesnt have links to profile) - links i need to save into google sheet)
- so next step is **SET** where im adding domain before, and paging after - [https://domain.com](https://domain.com){{$json[“data”]}}?page=
- next is **HTTP Request** where URL is {{$node[“Set”].json[“review.json”]}}{{$runIndex+1}} - runIndex starting from 0 and =page 0 and 1 are the same, so +1 is ok for me.
- next is **HTML Extract** where im extracting 1)links to profiles, 2)name of profile (this will be used in next step)
- next is **IF** - checking if json?page=1 has “name of profile” - if doesnt - workflow is stoping, if have “name of profile” it goes to next
- next **IF** - checking if exist “links to profile” - if no - return again to last HTTP Request - if it has “link to profile” it continue to
- **FUNCTION** where links are splitting into one url per line in json (links are without domain like /profileURL)
- so in next step **SET** - adding domain before link
- next writing links to **Google Sheet**. This first run goes ok.

As I mentioned - there are many json pages (.json?page=1, .json?page=2, etc, so im returning to

- **HTTP Request** again, to fetch next page {{$node[“Set”].json[“review.json”]}}{{$runIndex+1}} now sould return page=2, but here is an error and it looks like it forgot start URL

 ![x2UXz5eDQ7](https://europe1.discourse-cdn.com/n8n/original/2X/b/bda1e6eb82c51bfc500e8c33a6123044bc41b8f4.png)

Error when starting LOOP is:

 ![jkMZT7GdfD](https://europe1.discourse-cdn.com/n8n/original/2X/f/f7ef9c007fb696246b847709079ef05c0739f357.png)

Workflow:

What I need is to loop json pages till there will be no names and links in json file. At this moment this one has cca 240pages, but (half empty) json is generating even when trying page=999.

In close future i will need a hint how to read Google Sheet with many urls - one url per one workflow execution, then read next url. And how in this case about “runIndex”? how can i reset it? (on next ID/something.json file? becasue on next url i need to start it from zero again, and I plan to make this as loop too.

## Information on your n8n setup

- \*\*n8n version: 0.158.0
- \*\*Database you’re using (default: SQLite): PS
- **Running n8n with the execution process [own(default), main]:**
- \*\*Running n8n via [Docker, npm, n8n.cloud, desktop app]: docker

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [January 13, 2022, 8:45am UTC](https://community.n8n.io/t/http-html-extract-loop-problem/10562/2 "2022-01-13T08:45:03Z")

</div>

Hi @martin_sabo, welcome to the community 🎉

It looks like in your node `HTTP Request8` you are using an expression like `{{$node["Set"].json["review.json"]}}{{$runIndex+1}}`.

Based on your description it sounds to me like this is what is happening: When this node processes its first item, it would read the `review.json` property of the first item of your `Set` node. Once `HTTP Request8` processes its second item, it would try reading the second item of your `Set` node which doesn’t exist.

To always read the first item of your `Set` node, you can put $item(0) in front of your existing expression [as described here](https://docs.n8n.io/nodes/expressions.html#method-item-index-number-runindex-number).

Hope this helps 🙂

For your second question:

> a hint how to read Google Sheet with many urls - one url per one workflow execution, then read next url. And how in this case about “runIndex”? how can i reset it? (on next ID/something.json file? becasue on next url i need to start it from zero again, and I plan to make this as loop too.

May I ask why you want to execute a workflow many times? This seems like it complicates things a lot. That’s because almost all n8n nodes would run once for each item they receive. So when reading a Google Sheet like this:

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/e/ec1402ba8eef6fe6c65efa251837677850d2e828.png)

n8n would already make three individual HTTP requests using a simple workflow like this:

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/8/8fa29449181c884ea1ce860ecf499190d81a0dfb.png)

> **Example Workflow**
>

So purely based on the description it sounds to me like you wouldn’t need loops (and the headache that sometimes comes with them).

---

<div class="post-metadata">

**Author:** ![martin\_sabo](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/martin_sabo/32/9723_2.png) [@martin\_sabo](https://community.n8n.io/u/martin_sabo)\
**Post date:** [January 13, 2022, 9:17pm UTC](https://community.n8n.io/t/http-html-extract-loop-problem/10562/3 "2022-01-13T21:17:32Z")

</div>

Thank you for quick answer. After some testing i will choose a way with cron probably.

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [January 14, 2022, 8:24am UTC](https://community.n8n.io/t/http-html-extract-loop-problem/10562/4 "2022-01-14T08:24:50Z")

</div>

Hope my answer helped, enjoy your automation journey!
