Skip to content

πŸš€ Open-source Facebook comment exporter with nested reply support β€’ Vibe-coded through real-world DOM debugging β€’ Exports to CSV/JSON with hierarchical structure preservation

Notifications You must be signed in to change notification settings

disrex-group/FB-Comments-Exporter-User-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Facebook Comment Scraper Userscript

πŸŽ‰ Open Source β€’ Vibe Coded β€’ Community Driven

This project is built through iterative debugging, real-world testing, and community feedback. Every fix comes from actual Facebook DOM quirks discovered in the wild!


πŸ†• NEW: Visual Thread Viewer!

Export your Facebook comments and visualize them beautifully with our interactive thread viewer!

πŸ‘‰ Load your export at facebook-thread-viewer.lovable.app

✨ Features:

  • 🎨 Beautiful nested comment visualization
  • πŸ” Search and filter threads
  • πŸ“Š Thread analytics and insights
  • πŸ’Ύ Load JSON exports directly in your browser
  • πŸ“± Mobile-friendly responsive design

Simply export your comments using this scraper, then upload the JSON file to the viewer for a stunning visual representation!


πŸš€ Quickstart

  1. Install Extension: Tampermonkey (Chrome/Edge) or Greasemonkey (Firefox)
  2. Install Script: Click here to install the userscript
  3. Open any Facebook post with comments
  4. Click "Start Scraping" in the floating panel (top-right corner)
  5. Watch it work - automatically expands replies, detects nesting depth, highlights comments
  6. Auto-Export - JSON file downloads automatically when complete (no prompts!)
  7. πŸ†• Visualize (optional) - Upload your JSON export to facebook-thread-viewer.lovable.app for beautiful interactive visualization!

That's it! 🎯 The scraper handles nested replies, multi-level threads, and automatically downloads JSON - no clicking export buttons!


Overview

The Facebook Comment Scraper is a powerful userscript that enables you to scrape and export comments from Facebook posts, including full support for nested replies and hierarchical comment threads. It adds a floating interface to Facebook pages with automatic comment collection, depth detection, and export to both CSV and JSON formats.

Features

Core Functionality

  • Automatic Comment Scraping: Automatically scrolls through and collects comments from Facebook posts
  • Nested Reply Support: Full support for multi-level comment threads (replies to replies to replies...)
  • Depth Detection: Multiple strategies to detect comment nesting depth
  • Configurable Limit: Set a maximum number of comments to scrape (0 for unlimited)
  • Real-time Statistics: Shows progress including main comments, replies, and depth distribution

Export Capabilities

  • Auto-Download JSON: Automatically downloads JSON when scraping completes (no prompts!)
  • Hierarchical Structure: JSON export preserves full parent-child relationships and thread nesting
  • CSV Available: Manual CSV export option via browser console if needed
  • Rich Data: Includes author name, profile URL, profile image, timestamp, likes, comment text, depth level, detection method

Visual Features

  • Color-Coded Highlighting: Comments are highlighted by depth (red=main, orange=level 1, yellow=level 2, green=level 3+)
  • Real-time Progress: Live updates showing extraction progress and data quality stats
  • User-friendly Interface: Clean floating UI with easy-to-use controls

Advanced Detection

  • Multiple Detection Strategies:
    1. DOM Hierarchy (nested article elements)
    2. Aria-label Pattern Matching ("Antwoord van..." / "Reply from...")
    3. Author Mention Links
    4. Visual Indentation
    5. Container Grouping
  • Robust Author Extraction: Multiple fallback approaches to extract author names from various Facebook DOM structures
  • Debug Mode: Built-in diagnostic logging for troubleshooting

Installation

Prerequisites

One-Click Install

Click the button below to install the Facebook Comment Scraper:

Install Facebook Comment Scraper

Manual Installation

  1. Install Tampermonkey or Greasemonkey for your browser
  2. Navigate to the raw userscript file
  3. Your userscript manager will prompt you to install it
  4. Click "Install" to add the script

Usage

  1. Navigate to any Facebook post (works on both www.facebook.com and m.facebook.com)
  2. You'll see a floating panel in the top-right corner of the page
  3. Set the maximum number of comments to scrape (or 0 for unlimited)
  4. Click "Start Scraping" to begin collecting comments
  5. The script will automatically:
    • Expand comment sections
    • Load more comments
    • Expand replies (including nested replies)
    • Detect comment depth and hierarchy
    • Collect comprehensive comment data
    • Download JSON export when complete (no additional clicks needed!)
  6. Watch the real-time statistics showing main comments, replies, and depth distribution
  7. The JSON file (fb_modal_YYYY-MM-DD.json) downloads automatically to your browser's download folder
  8. Check the browser console (F12) for detailed statistics and logs

Scraped Data

The exported files include:

All Formats

  • Author Name: Commenter's display name
  • Profile URL: Link to commenter's Facebook profile
  • Profile Image: URL to profile picture
  • Comment Text: Full comment content
  • Timestamp: When the comment was posted
  • Likes: Number of reactions
  • Depth: Nesting level (0=main comment, 1=direct reply, 2=reply to reply, etc.)
  • Detection Method: How the depth was determined

JSON Export (Additional)

  • Hierarchical Structure: Nested replies under parent comments
  • Parent ID: Reference to parent comment
  • Reply To Author: Name of the author being replied to

Version History

v1.1 (Current)

  • πŸš€ Auto-download JSON export - No more confirmation dialogs! JSON downloads automatically when scraping completes
  • βœ… Stats logged to console instead of alert dialogs
  • βœ… Cleaner UX - no interruptions, just automatic export

v1.0 (Initial Release)

  • πŸŽ‰ Initial public release on GitHub!
  • βœ… Multi-level nested reply detection (DOM hierarchy + aria-label patterns)
  • βœ… Dual export formats: CSV (flat) and JSON (hierarchical)
  • βœ… Color-coded depth visualization
  • βœ… Robust author extraction with multiple fallback strategies
  • βœ… Profile link handling (supports query parameters)
  • βœ… Smart name filtering (handles Dutch/English, timestamps, special characters)
  • βœ… Support for both "Opmerking" (Comment) and "Antwoord" (Reply) aria-labels
  • βœ… Real-time scraping statistics and progress tracking
  • βœ… Debug mode for troubleshooting
  • βœ… Automatic depth detection using 5 different strategies

Known Limitations

  • Requires comments to be loaded in the Facebook modal/dialog
  • Facebook's dynamic DOM structure may require periodic updates
  • Very large comment threads (1000+ comments) may take time to process
  • Facebook rate limiting may affect scraping speed

Debugging

Enable debug mode by setting window.DEPTH_DEBUG = true in the browser console before scraping. This will output detailed logs about:

  • Depth detection strategies used
  • Author extraction attempts
  • DOM structure analysis
  • Parent-child relationship matching

Updates

The userscript includes automatic update checks. Your userscript manager will notify you when a new version is available.

Contributing

Found a bug? Facebook changed their DOM structure again?

This is an opensource, vibe-coded project - every fix comes from real-world testing! Feel free to:

  • Report issues with specific Facebook posts
  • Share console output for debugging
  • Submit fixes for edge cases
  • Suggest improvements

Author

Rick - r.bouma@disrex.nl

Version

Current version: 1.1

License

Open Source - Built with community feedback and iterative debugging! πŸš€

About

πŸš€ Open-source Facebook comment exporter with nested reply support β€’ Vibe-coded through real-world DOM debugging β€’ Exports to CSV/JSON with hierarchical structure preservation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •