insta-prune — Scripts

launch-4.py is the current main script. Earlier versions (launch.py, launch-1.py, launch-2.py) are kept for reference.

launch-4.py — Automated Unfollow Loop

Unfollows every account on john_appreciates one at a time, in order of the following list, until the following count reaches zero.

Configuration

PAUSE env var — seconds to wait between iterations (default 6). Example: PAUSE=10 python launch-4.py

Flow per iteration

1. Load profile page https://www.instagram.com/john_appreciates/

2. Read following count from the header span. If 0, stop.

3. Click the following count to open the following list dialog.

4. Wait for dialog entries (buttons with class _ap3a) to appear.

5. Extract the first user's profile URL and append it to profile_urls file (one URL per line, duplicates OK — use uniq later).

6. Read the first entry's button text:

- Following → click it, wait for Unfollow confirmation dialog, click Unfollow, wait for button to flip to Follow.

- Follow → the account is already not followed; close dialog with the X button.

- Anything else → unexpected state; save screenshot + HTML as evidence, then close dialog.

7. Wait PAUSE seconds, then repeat.

Output files

profile_urls — one Instagram profile URL per line for every account processed.

screenshot-NNN-<label>.png / page-NNN-<label>.html — screenshot and HTML saved at every key step (profile load, following list, before/after each click). Zero-padded 3-digit step counter.

Key XPaths

- Following count: //a[contains(@href,'/following/')]//span[contains(@class,'html-span')]

- Dialog: //div[@role='dialog']

- Entry buttons: //div[@role='dialog']//div[contains(@class,'_ap3a')]

- Unfollow confirm button: //button[text()='Unfollow']

- Close dialog: //div[@role='dialog']//button[.//*[@aria-label='Close']]

Known issues / TODO

- Approval-required accounts: some private accounts may show a different confirmation when unfollowing ("you'll have to re-request"). The script hits the unexpected-state branch and saves evidence. Not yet handled.

version1
created2026-03-15