Instagram profile scraper: export from a list of handles
This Python script looks up a list of public Instagram accounts and saves their profiles to a CSV file. Each account is one call at $0.0011, so 100 accounts that are found cost $0.11. A handle that isn't found is marked in the file and isn't charged.
The endpoint's page covers a single request. Here you get a whole list of accounts in one file, each looked up once, with handles that aren't found marked.
What one real run got
Run on 2026-11-29, exactly as printed below. Five public organizations: nasa, unicef, natgeo, metmuseum and who. It made 5 calls, wrote 5 rows and cost $0.0100.
handle,found,name,verified,private,followers,following,website,bio nasa,yes,NASA,True,False,104249725,91,https://www.nasa.gov,"Making the seemingly impossible, possible. ✨" unicef,yes,UNICEF,True,False,11170358,299,https://linktr.ee/for_every_child,UNICEF works in over 190 countries and territories to protect… natgeo,yes,National Geographic,True,False,267171261,195,http://visitstore.bio/natgeo,Step into wonder and find your inner explorer with National…
Rows from the file it wrote. Long text is cut short here; the file has all of it.
The whole script
Save this as export.py and change the settings at the top. Install the SDK, set your key as the first two lines show, then run python3 export.py. You need Python 3.9 or later. The CSV file is saved in the folder you run it from. At the end, the script shows how many calls it made, how many rows it wrote and what was charged.
# Python 3.9 or later. First: python3 -m pip install dataxapi # and: export DATAXAPI_API_KEY=dx_... (your key) import csv import sys from decimal import Decimal from dataxapi import APIConnectionError, DataXAPI, DataXAPIError, NotFoundError HANDLES = ["nasa", "unicef", "natgeo", "metmuseum", "who"] # with or without the @, one call each MAX_CALLS = 10 # the run stops here, whatever is left OUT = "instagram_profiles.csv" # a new file: the run won't replace one SHEET_SAFE = True # puts ' before text a spreadsheet could run as a formula; False keeps it as it is dx = DataXAPI() calls, charged, seen, more, problem = 0, Decimal("0"), set(), False, None class OutOfCalls(Exception): pass def call(capability, params): """One call, never more than MAX_CALLS of them, failed ones included; adds up what they were charged.""" global calls, charged if calls >= MAX_CALLS: raise OutOfCalls calls += 1 result = dx.call(capability, params) charged += Decimal(str(result["meta"]["billing"]["amount"])) return result def cell(value): """Text that begins as a formula does gets a ' before it, so a spreadsheet shows it and does not run it.""" if SHEET_SAFE and isinstance(value, str) and value.lstrip(" ").startswith(("=", "+", "-", "@", "\t", "\r", "\n", "=", "+", "-", "@")): return "'" + value return value with open(OUT, "x", newline="", encoding="utf-8") as file: out = csv.writer(file) out.writerow(["handle", "found", "name", "verified", "private", "followers", "following", "website", "bio"]) try: # Each handle once, however it is written, and no empty ones. for handle in dict.fromkeys(each.strip().lstrip("@").lower() for each in HANDLES): if not handle: continue try: item = call("instagram.users.get", {"username": handle, "view": "full"})["data"]["item"] metrics, ext = item.get("metrics") or {}, item.get("ext") or {} row = ["yes", cell(item.get("name")), item.get("verified"), ext.get("is_private"), metrics.get("followers"), metrics.get("following"), cell(ext.get("website")), cell(item.get("bio"))] except NotFoundError as error: if error.unsettled: raise # an earlier try of this call got no answer: what it was charged isn't known row = ["no"] + [""] * 7 # no such account, or it is gone: kept in the file, and not charged out.writerow([cell(handle)] + row) seen.add(handle) file.flush() except OutOfCalls: more = True except (DataXAPIError, APIConnectionError) as error: problem = error print(f"calls: {calls}, rows: {len(seen)}, charged: ${charged}" + (", and there is more to get" if more else "")) if problem: print(f"Stopped by an error; the rows above are saved. {problem}") if problem.unsettled: print("The last call may have been charged. Check your call history before you run this again.") sys.exit(1)
Open the file safely
Anyone can start a comment, caption or bio with =, +, - or @, and a spreadsheet may run it as a formula. SHEET_SAFE puts ' before text like that. If you set it to False, don't open the file by double-clicking it. Some IDs are long numbers, which a spreadsheet may round. To keep them exact, use its CSV import and set the ID, handle and text columns to Text.
If it stops early
MAX_CALLS counts every call, including failed ones. If the SDK tries a call again, it still counts as one. If a call fails, the script stops, keeps the rows it has and shows what it knows was charged. If the connection drops before an answer arrives, that call may still have been charged. The script tells you, so check your call history before you run it again. It never replaces a file: for another run, change OUT or move the old file.
What it costs
These are the costs when every handle is found. To track changes, use the same list each time and put the date in OUT. Prices are the ones in force when this page was built.
What is in the file
handleThe handle you asked for, in lower case and without the @foundyes, or no when the handle wasn't foundnameThe account's display nameverifiedWhether Instagram has verified itprivateWhether its posts are privatefollowersHow many accounts follow itfollowingHow many accounts it followswebsiteThe website on its profile; may be emptybioIts bioHow it works
- Put the exact handles in
HANDLES; it doesn't search by name. You can include the @ or use capitals. The script removes the @, makes the handles lower case, skips empty ones and looks up each one once. - It makes one call for each handle. If one isn't found, it writes
noand goes on to the next. MAX_CALLScounts every lookup, including handles that aren't found. Set it to at least the number of handles in your list.
What to know first
- Use it for brands and organizations you have a reason to look up, not to build profiles of private people. It includes the public part of a private account's profile, but not its posts.
- The result doesn't include the number of posts or any email address or phone number. A bio can still contain details someone chose to make public; keep only what you need.
- Check
verified, the name and the website before you use a result. A similar handle may belong to someone else.