How to scrape Instagram followers with an API (Python & Node)
Instagram has no official way to export a public account’s follower list — the Graph API only reaches accounts that authorize your app. A data API solves it: you call one endpoint, page through the result, and get a clean list of accounts. This walks through doing it with herascrape in Python and Node.
1. Get the account’s numeric id
The followers endpoint takes a numeric user id (the pk), not a username. Resolve it once with the profile endpoint:
curl "https://api.herascrape.com/users/username/nasa" \
-H "x-api-key: $HERASCRAPE_KEY"
# -> { "pk": "528817151", "username": "nasa", "follower_count": 97412883, ... }Keep the pk — you’ll pass it to every follower request.
2. Page through the followers
GET /users/{id}/followers returns one page of followers in a uniform envelope: { items, next_cursor, has_more }. Loop on next_cursor until has_more is false.
Python
import os, httpx
KEY = os.environ["HERASCRAPE_KEY"]
BASE = "https://api.herascrape.com"
def followers(user_id: str):
cursor = None
with httpx.Client(headers={"x-api-key": KEY}) as client:
while True:
params = {"cursor": cursor} if cursor else {}
r = client.get(f"{BASE}/users/{user_id}/followers", params=params)
r.raise_for_status()
page = r.json()
yield from page["items"]
if not page["has_more"]:
return
cursor = page["next_cursor"]
for user in followers("528817151"):
print(user["username"], user["pk"])Node
const KEY = process.env.HERASCRAPE_KEY;
const BASE = "https://api.herascrape.com";
async function* followers(userId) {
let cursor;
do {
const url = new URL(`${BASE}/users/${userId}/followers`);
if (cursor) url.searchParams.set("cursor", cursor);
const res = await fetch(url, { headers: { "x-api-key": KEY } });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const page = await res.json();
yield* page.items;
cursor = page.has_more ? page.next_cursor : null;
} while (cursor);
}
for await (const user of followers("528817151")) {
console.log(user.username, user.pk);
}What each follower looks like
{
"pk": "1903080852",
"username": "spacex",
"full_name": "SpaceX",
"is_verified": true,
"is_private": false
}Rate limits and billing
- The default rate limit is 50 requests per second per API key; exceed it and you get a
429, which is not billed. Ask and it can be raised. - Only successful
2xxcalls cost anything — one request is $0.0004 ($0.40 per 1,000), flat. - For very large or business accounts, Instagram caps how deep follower pagination can go, so the full list may not be reachable — the loop simply ends when
has_moreturns false.
Next steps
The same cursor pattern works for following, comments and every other list endpoint. See the followers scraper use case for the full field reference, or the pagination guide in the docs.