N8N

N8N Scrape Instagram

There are countless ways in which you can scrape Instagram for leads with N8N

This article and guide will showcase one approach in which we scrape hashtags to find accounts and then extract account information.

*Instagram Hashtag Scraper: https://console.apify.com/actors/reGe1ST3OBgYZSsZJ/input?fpr=xpluxt *Instagram Profile Scraper: https://apify.com/apify/instagram-profile-scraper?fpr=xpluxt

Hire me for N8N Automations: https://ryanandmattdatascience.com/hire-n8n-automation-engineer/

This workflow uses N8N to scrape Hashtags and the profiles that have posts with them. From there it grabs those profiles and gets follower counts and bios from another Apify Actor.

Once we have the Actor, we then will want to grab the datapoints we want to use and then filter down to accounts with a certain amount of followers. Then we add to sheets.

Form Trigger

To start this workflow, we are going to accept a form input from the user. Here a user can define what hashtag we want to scrape for the accounts.

Actor 1 - Hashtags

We are going to use the new N8N Apify Nodes to get the posts for a hashtag. To do so we will first run an actor.

After running the actor, we need to grab the dataset associated with it. 

Edit Fields & Code Node

Since we are only targeting the usernames that posted for the hashtag specified earlier, let’s edit the fields and only keep this datapoint.

With some basic list comprehension we can now work on getting a list of username ids together for our next Apify Actor.

				
					# Input: items array with field ownerUsername
# Output: list of usernames

usernames = [item["json"]["ownerUsername"] for item in items]

return [{"json": {"usernames": usernames}}]
				
			

Actor 2- Instagram Account Info

Now lets get the account info. We will run the Apify Instagram Account Scraper with the help of the Run Actor and Get Dataset nodes once again. 

Get Dataset Node

Edit Fields & Filter

Like earlier, we won’t need all the fields. We can edit them down to the following 4. 

Now let’s filter the results of what is added into the sheet. We want to only have accounts that have over 500 followers and are not private. To do this use a filter node.

Append to Sheets

With our final results, let’s now append the results to a Google Sheet.

Final Thoughts

That’s it. Not too complicated of a workflow, but there are a ton of ways in which you can really expand it out. If you need any help with your N8N workflows, hit us up.

Ryan is a Data Scientist at a fintech company, where he focuses on fraud prevention in underwriting and risk. Before that, he worked as a Data Analyst at a tax software company. He holds a degree in Electrical Engineering from UCF.

Leave a Reply

Your email address will not be published. Required fields are marked *