Lead Scraping & Lead Generation
Everything from Claude Code and Codex sessions, Apr – Nov 2026. Compiled 26 Nov 2026. Secrets and scraped contact details left out; counts only.
leadgen_leads rows (Jul 23)In one line: started with Apify-heavy Instagram creator scraping, moved profile enrichment to Meta Graph then Cloudflare Browser Rendering (near-free), then shifted discovery to agent-driven web research (Linktree, agencies, storefronts, Meta Ad Library) and an autonomous outbound agent (Harvey). Cold email to generic inboxes has produced no replies so far.
Architecture evolution
| When | Approach | Status |
|---|---|---|
| Apr 2026 | Standalone lead-generation repo (FastAPI + Next.js), Apify discovery + instagrapi enrichment, 100-pt scoring, Resend emails | parked |
| May 16 | Pipeline moved into Flask leadgen/ + /api/leadgen/* (flask#147); CRM lead-gen pages | live on beta |
| Jun | Internal cohort leads from workspaces_new (Link-in-bio, halted automations) | live prod |
| Jul 5–10 | ZOR-305: replace Apify profile fetch with Meta business_discovery via Zorcha AI tokens; CRM hourly cron → ai_personas | fallback only |
| Jul 11+ | Cloudflare Browser Run inside CRM worker + Instagram public web_profile_info JSON; Google-indexed discovery option | cron failing Sep 11 |
| Jul 22 | Standalone scraper Worker: public JSON → embed HTML → Browser Run fallback (crm#452) | healthy |
| Jul 23–24 | Agent-driven web research: Linktree + wa.me, Stan storefronts, agency websites | one-off |
| Sep 16–17 | lead-generation agency mode; Apify replaced with free web search (PR #4 open) | unmerged |
| Oct | SuperProfile/Topmate storefront research → Sheets; then mining existing Zorcha sellers | one-off |
| Oct 14 – Nov | Harvey autonomous outbound agent (Serper / DDG via Cloudflare, Meta Ad Library, Reoon, Gmail warm inboxes) | active |
Systems
1. lead-generation repo (Zorcha/zorcha-lead-gen)
Purpose: find IG creators selling digital products with "comment LINK below" triggers; score; email.
Stack: FastAPI + SQLAlchemy + asyncio · Next.js 16 / React 19 / shadcn · Tiptap editor · WebSocket run logs · Resend (cold + transactional accounts).
Stores: leadgen.db (runs, leads, emails, reports), raw_datalake.db (raw Apify responses → re-score without re-scraping). Postgres via DATABASE_URL since Apr 11.
Run: .env with APIFY_API_TOKEN (+ optional OpenAI/Resend) → bash start-pm2.sh (API :8000, UI :3000). GH Actions → EC2 pm2.
Agency mode (Sep 16–17, Claude):
- Discovery:
site:linkedin.com/company "<query>" <city>, query × city buckets interleaved. - Site crawl of agency domain (home/about/team). Contacts from
site:linkedin.com/in "<company>" foundersnippets — no LinkedIn requests. - Phones:
tel:/wa.me→ contact page → regex, E.164. - IG-focus gate: agency evidence + IG signal (instagram/reels/influencer/ugc/personal branding) or own IG ≥500 followers.
- First version used paid Apify actors (Google SERP, LinkedIn company ~$3/1k, employees ~$4/1k); rewritten to free web search on user request.
- Free run: 6 agencies, 18 contacts, 5 emails in ~3 min. IG-focused run: 51 found → 13 leads, 21 contacts, phones 3/13.
2. Flask leadgen module (zorcha_flask)
14+ endpoints under /api/leadgen/: health, runs (list/get/delete/create), leads (list/get/enrich), config (get/put), stats, usage, export. CRM pages under zorcha-crm app/routes/dashboard/lead-gen/ proxy it. "New Run" modal supports discovery_source = hybrid / google_indexed / apify.
Detailed write-up: zorcha_flask_leadgen_outreach_pr/leadgen_pipeline_stages.md
3. lead-gen-test (measurement only)
queries.txt (e.g. site:instagram.com/reel/ "comment LINK" after:2026-01-01). npm run google|full|all -- --country us → reports/<ts>/report.html|json, leads.csv. First Google-only probe hit CAPTCHA, 0 links. Inspired Google-indexed discovery in Flask; not ported.Flask pipeline stages
leadgen_kv)→1 · Apify discovery→2 · profile enrich→3 · follower filter→4 · classify, contacts, score, LLM report→5 · usage metrics| Stage | Detail |
|---|---|
| 0 | Load run config/budget; stop early if lifetime Apify budget exhausted. |
| 1 Discovery | patient_discovery/instagram-search-reels (richest, virality metrics) · sasky/instagram-keyword-posts-urls-scraper (3 months) · apify/instagram-hashtag-scraper. Dedupe by owner: reels > keyword > hashtag. Alt: Google CSE indexed discovery. |
| 2 Enrich | Originally instagrapi + 7-day profile_cache, 2–5 s jitter, account rotation (#192). Later: profile_cache → Meta business_discovery → Cloudflare scraper. |
| 3 Filter | min/max followers (min_followers: 0 or 1000 default bug fixed). |
| 4 Qualify | Optional India filter (later: tag country_hint=india_hint instead of skip). Caption tiers T1 explicit comment-to-DM, T2 ManyChat/Chatfuel, T3 "link in bio", T0 skipped. Viral comment detector (≥30% same short word → T1). Email from bio (incl. at/dot obfuscation) + website + ≤2 contact pages. Phone via phonenumbers. Deep enrich Linktree/Beacons/Stan → SERP fallback. LLM report "The Gap" + "Outreach Hook". |
| 5 | Persist Apify units, OpenAI tokens/cost. |
Scoring & ICP
| Creator score (100 pts) | Pts |
|---|---|
| Content / intent | 35 |
| Automation maturity | 30 |
| Virality | 17 |
| Account health | 14 |
| Audience (penalty >1M) | 8 |
Tiers: Hot ≥60 (auto-queued for OpenAI research report), Warm 35–59, Cold <35. Brand accounts filtered. AgencyScorer: IG focus, contacts, email, website, 5–200 staff. profile_type = business / creator / personal / unknown from web_profile_info.
Cloudflare scraping
Standalone Worker zorcha-leadgen-browser-scraper-beta — scraper-only, no Postgres, BROWSER binding only. POST /api/internal/leadgen/browser-run/preview-profile, bearer LEADGEN_BROWSER_RUN_TOKEN (timing-safe compare), host allowlist. Order: IG public JSON → embed HTML → Browser Run.
CRM hydration cron in zorcha-crm, 0 * * * *, runLeadgenProfileHydrationCron. Candidates: raw_posts usernames with no profile_cache row in 30 days, max 50/batch. Writes only profile_cache, never leadgen_leads. Manual trigger POST /api/internal/leadgen/profile-hydration/run. Sep 11: 50 selected / 0 hydrated / 50 failed (Browser Run WebSocket errors). crm#568 (Sep 30) moved it to admin DB; not re-verified.
Why web_profile_info: SEO meta tags gave bio + counts but 0/25 external URLs. JSON gives external_url, bio_links, business/professional flags, category, business email/phone. Validation vs 25 known leads: 25/25 hydrated, 14/16 bio emails recovered.
Review hardening (crm, 4 rounds): public contacts only if should_show_public_contacts === true; sparse embeds never overwrite cache; libphonenumber to reject order IDs/ISBNs/timestamps; embed captions only when owner matches.
Limits: Workers fetching Instagram directly hit login redirects + 429s; follower counts sometimes needed real browser checks. Reel view counts not collected (needed for a Modash-style avg-views calculator).
Discovery waves
| Date | Target | Method | Result |
|---|---|---|---|
| Jul 11–26 | Comment-to-DM creators, competitor users (ManyChat/Wishlink) | Flask hybrid Google/Apify + Cloudflare hydration | Competitor run 19 leads / 5 emails. 1,000 push: 794 leads, 34 emails, 0 phones (stopped on Meta Graph limits) |
| Jul 21–22 | Phones for existing leads | bio_links, wa.me, tel:, website contact pages, JSON-LD; backfill_leadgen_phone_cache.py (dry-run, --apply) | +24 phones on beta (25 total) |
| Jul 23 | Phone-rich IG creators, 6 regions | Live Linktree pages with IG + wa.me; country from calling code | 180 usernames (30/region) |
| Jul 23 | ManyChat-style creators | Stan storefronts + 2026-indexed search | 25 (stopped early; weak ManyChat evidence) |
| Jul 24 | IG-focused agencies (ME, EU, Americas, Africa) | First-party agency websites, 1,255-name exclusion list | 90 validated; beta agency phones 4 → 130 (117 Hot); 76 emails + 67 contact forms not attached to DB |
| Sep 5 | Mumbai finance creators already on Zorcha | Internal: bios, DM-geo aggregates, follower-city insights, PostHog geo | 123 accounts (9 self-stated Maharashtra); skill zorcha-brand-collab-discovery (support_agent#115) |
| Oct 2–8 | SuperProfile / Topmate sellers | 3-stage CF Worker + D1 (crm#574 draft); search-indexed pages (Vercel checkpoint blocked live); storefront → product → seller-support | 609 records, 503 product prospects, 204-number phone sheet; 47 India ₹500+ sellers; 130 IG handles |
| Oct 8 | Existing Zorcha paid sellers | Internal DB + ban/availability checks | 182 verified paid sellers → Sheets for sales |
Harvey outbound agent (Oct 14 – Nov)
Fork of ethanplusai/harvey at z/harvey (local zorcha branch). Python, SQLite, dashboard :5555. Loop: discover → profile → enrich → verify → write → send, each message must pass harvey.gate. Zorcha additions: IG/FB signals, harvey import <csv>, SMTP reply-to, footer.
Sources: Serper (Google) · httpx site profiling · Cloudflare Browser Rendering + DuckDuckGo (after Serper credits hit 0) · Meta Ad Library (no login) → advertiser FB page contact info · Reoon email verification · PostHog check to exclude existing users.
Sending: Resend from send.zorcha.com, then Gmail-scheduled from warmed zorcha.app (~15/day) and zorcha.ai (~5/day) inboxes via browser control.
| Date | Run | Numbers |
|---|---|---|
| Oct 15–16 | UAE businesses | 152 profiled → 47 Resend sends; +351 companies found, 200 profiled (per-run cap) |
| Oct 17 | Built-in contact finder | Person found at 4 of ~90 businesses |
| Oct 31 | Owner research | 118 businesses → owners for 57 (48%) |
| Nov 6 | Owner research + Reoon | +114 owners (171 total); 20 Reoon checks: 3 safe, 10 invalid, 2 spam traps; Meta Ad Library test: 28 UAE click-to-chat advertisers |
| Nov 11–15 | Gmail warmup sends | 162 sent from zorcha.app; 22 follow-ups; 1 bounce, 0 replies |
| Nov 18 | US niches | 174 profiles → 159 Reoon-safe emails; held (needs CAN-SPAM postal address) |
| Nov 19 | India pivot (85% of paid users in India) | Meta Ad Library "bridal makeup delhi" ~960 ads → 35 advertisers → 17 safe emails, scheduled Nov 22–23 |
| Nov 22 | Reply check | 226 contacted, 0 replies. India batch to judge ~Nov 26–27 |
Email outreach (Flask)
app/leadgen_email_sender.py+ Celeryleadgen_send_email_queue, every minute fromrecurring.py. Admin-DBemailstable = queue (queued → sending → sent). Resend/emails/batch(100/batch, 10 req/s). Suggested cold pace: batch 50, 30 s gaps, 500–1,000/day; in practice 15-min gaps.- Resend webhook
/api/webhook/resend/bounce(flask#279, #319 prod 500 fix): Svix-signed; bounced → marked in leadgen emails +users. Signing secret in SSM. No extra suppression table (ponytail): block onemails.status='bounced'+leadgen_leads.metadata.email_bounced. - CRM Gmail compose button with
gmail_clickedtracking (crm#426 / flask#286); phone + agency filters (#457); SQL-backed sort. - Results: first 10 delivered, landed in Gmail Promotions. Short plain human note → Inbox. 18 sent + 13 queued;
scheduled_attext-type bug fixed in #299. Helperscripts/schedule_leadgen_emails.py(dry-run /--apply),leadgen/outreach_playbook.md.
Internal cohort leads (no scraping)
- Link-in-bio leads (Jun 19–20): workspaces whose
channel_info.websiteis linktree / wishlink / superprofile. 1,041 on prod (741 / 182 / 118). processor#537/#541, crm#319/#320/#322. Sep 19 processor#818 marks success on page publish. - Halted automations: non-paid + HALTED automations; 42 reopened, 312 open (Aug 16).
- Banned leads (Nov 23): processor#1066 merged not deployed; 269 prod leads filled by hand.
Instagram ban scraper
zorcha_scripts/check_paid_past_instagram_ban_status.ts + instagram_validity_worker.ts. Cloudflare Browser Rendering probes public profile → workspaces_new.is_banned timestamp (schema#82): banned → NOW(), valid → NULL, unknown untouched. Dry-run default, --apply, --segment=sleeping-leads-5k. Prod Sep 7: 4,100 → 737 banned / 2,557 valid / 806 unknown. Limit: DM-restricted accounts look normal publicly (anonymous probe caught 0 of 38 confirmed bans); real signal is Meta error 368.Data stores
| Store | Holds |
|---|---|
| Admin Postgres (beta / prod) | raw_posts (discovered usernames, acts as queue), profile_cache, leadgen_runs, leadgen_leads (phone_number, metadata.phone_source, cloudflare_instagram_profile, country_hint, automation post), emails, CRM leads |
| Main DB | ai_personas (hydrated profile facts), workspaces_new.is_banned, users bounce fields |
| D1 / KV | SuperProfile pipeline; beta.zorcha.link preview pages |
| Google Sheets | SuperProfile, agency and seller lead lists shared with sales |
| Local | harvey/data/ (git-ignored), lead-generation/backend/output/*.csv, support_agent/reports/…, reports/… |
Costs
- Cloudflare Browser Run: ~$0.000015/profile. 794 profiles = 0.616 browser-hours ≈ $0.055. 334-lead run via JSON-first worker ≈ $0.0001. 10 h/month included, then $0.09/h.
- Zorcha CF account Sep: 20.9k sessions, 24.52 browser-hours. Invoice Jul $12 → Sep $32, driven by Observability Logs more than Browser Run.
- Apify was the main cost driver (reason for ZOR-305); LinkedIn actors ~$3–4 per 1k.
- Harvey: Serper credits exhausted; 10,000 Reoon credits bought (~8.8k left).
Timeline
| Date | Event |
|---|---|
| Apr 4–12 | lead-generation built: dashboard, Postgres, Tiptap, dual Resend, EC2 CI/CD |
| May 16–21 | Pipeline into Flask (flask#147); instagrapi rotation (#192) |
| Jun 19–21 | Link-in-bio leads; emails table + Apify concurrency (flask#256) |
| Jul 5–10 | ZOR-305 hydration design: Meta Graph + CRM cron |
| Jul 11–13 | Flask discovery + email queue (#278); Cloudflare Browser Run in CRM; first 10 cold emails |
| Jul 16–26 | Gmail button, phone recovery, standalone scraper (crm#452), 794-lead push, Resend webhooks, outreach docs (docs#121) |
| Jul 23–24 | Linktree/Stan/agency discovery waves; beta leads 921, agency phones 130 |
| Aug 4 | Resend bounce webhook prod fix (#319) |
| Sep 5–7 | Brand-collab creator skill; IG ban scraper prod run |
| Sep 11 | CRM hydration cron found failing 50/50 |
| Sep 16–17 | Agency mode; Apify removed (PR #4); Browser Run access for Harsh |
| Sep 30 | Hydration cron to admin DB (crm#568) |
| Oct 2–8 | SuperProfile/Topmate discovery; 182 verified paid Zorcha sellers |
| Oct 14 – Nov 22 | Harvey: UAE → owners → US (held) → India Meta-ads; 226 sent, 0 replies |
Current state
| Item | State |
|---|---|
| Link-in-bio CRM leads | live prod |
| Flask leadgen API + Resend queue + webhooks | beta webhook on prod |
| Standalone CF scraper Worker | healthy |
| CRM hydration cron | failing Sep 11 fix #568 unverified |
lead-generation agency mode (free search) | PR #4 open 11 uncommitted files |
| Harvey | active India batch pending judgement |
| Meta Graph hydration / Apify | fallback |
lead-gen-test, FastAPI SQLite mode | abandoned |
Open items
- Nothing writes standalone scraper results into
leadgen_leads; hydration never creates leads. - CRM hydration cron Browser Run WebSocket failures — verify after crm#568.
- Agency emails (76) + contact forms (67) not attached to
leadgen_leads. - Emails queued in beta admin DB never drain (prod cron points at prod admin). No unsubscribe header; no reply tracking.
- Hardcoded legacy Resend key in a tracked Flask helper; several keys pasted in chats (Cloudflare, Serper, Reoon) and in old memory — rotate.
- Flask open PRs: #281 Resend events, #188, #257 Apify quota fail-fast, #210 SSM mapping. Processor #537/#541 not on main.
- Beta Flask leadgen endpoints have no own auth; daemon-thread runs lost on restart and stale runs eat 5-run limit.
- SuperProfile migration previews blocked (frontend#803 404, importer 403); crm#574 draft.
- Harvey: 159 US leads held for CAN-SPAM address; Gmail API sending needs user-owned Google Cloud OAuth.
- IG ban: refresh
is_bannedin update-user-details path; periodic revival re-check.
Lessons
- Google blocks fast. CAPTCHA on first probe, 429s on agency runs. Serper credits run out; DDG via Cloudflare Browser Rendering works as fallback.
- LinkedIn: no direct scraping (login walls). Search snippets give names; verify title/company match.
- Tight ICP gate needed. "Marketing agency" queries return IT/import firms; require agency words + IG signal.
- Generic inboxes don't reply. 226+ cold emails, 0 replies. Better: verified owners, businesses already paying for click-to-chat ads, India market.
- Deliverability: product-heavy copy → Promotions; short human notes → Inbox. Warm separate domains, respect warmup limits.
- Env mismatch kills pipelines: rows in beta DB, cron on prod. Confirm stage before prod sends.
- Defensive guards hide failures: ban scraper "ran 10 s and did nothing". Enable per-worker observability.
- Scraped lists are not opt-in: no bulk sends, keep out of git, never re-send to bounced addresses.
- Cheapest path first: public JSON before headless browser cut Browser Run cost to ~0.
Runbook
| Task | How |
|---|---|
| Trigger prod CRM lead pipeline | Queue run_leads_pipeline; check scheduler_logs queue_leads_pipeline | COMPLETED |
| Local lead generation test | cd zorcha_processor/event-handling/processor && STAGE=beta PYTHONPATH="$(pwd):$(dirname "$(pwd)")" python3 local_test.py leads_generation |
| Start standalone lead-gen app | cd lead-generation && bash start-pm2.sh |
| Schedule leadgen emails | python scripts/schedule_leadgen_emails.py (dry-run), add --apply |
| Phone backfill | scripts_unreferenced/backfill_leadgen_phone_cache.py --run-id … --limit …, then --apply |
| IG ban check | zorcha_scripts/check_paid_past_instagram_ban_status.ts [--segment=sleeping-leads-5k] [--apply] |
| Manual hydration | POST /api/internal/leadgen/profile-hydration/run (bearer) on CRM worker |
Sources
Codex threads (19): Link In Bio leads, Replace Apify profile fetch / Lead gen BRo, Design lead email pipeline, Trace browser scraper flow, Inspect beta candidates, Safe phone backfill, Review IG scraper diff, Find 150 IG leads ×2, Discovery entrypoints, Audit beta leadgen data, Agency leads ×2, Creator search skill, Check Cloudflare scraping ×2, SuperProfile discovery. Claude Code sessions Sep–Nov (agency mode, Harvey, link-in-bio success, ban detection). Repos: lead-generation, lead-gen-test, zorcha_flask leadgen, zorcha-crm, zorcha_scripts, harvey. Docs: leadgen_pipeline_stages.md, leadgen/outreach_playbook.md, zorcha-docs LEADGEN_CURRENT_STATE.md.