Skip to content

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

DeepDive Goblin Scrape

An AI-powered, multi-source scraping tool that works as an MCP server for agents. Give it a topic and it will:

  1. Generate smart keywords using a local LLM (OpenAI-compatible endpoint at localhost:8888/v1).
  2. Scrape the Web (Google / Bing / DuckDuckGo search + headless browser content extraction).
  3. Scrape X / Twitter via rotating Nitter instances.
  4. Scrape Reddit via PRAW.
  5. Search YouTube and extract video transcripts.
  6. Synthesize everything into a deep-dive report using the local LLM.

Built with Python 3.12+, asyncio, Playwright (+ stealth), BeautifulSoup4, PRAW, youtube-transcript-api, Typer, and the official mcp library.


Table of Contents


Features

  • Multi-source deep dives — Web, X/Twitter (Nitter), Reddit, and YouTube in one pass.
  • Local-first LLM — keyword generation and report synthesis against http://localhost:8888/v1 (e.g. Qwen3.6). No cloud API keys needed.
  • Concurrent scraping — all sources run concurrently via asyncio.gather() with configurable concurrency and rate limiting (jittered delays).
  • Graceful degradation — if one source fails, the others keep going and the report still gets produced.
  • Anti-detect headless browsing — Playwright + playwright-stealth with realistic browser headers generated via faker.
  • Robust exports — JSON, CSV, Parquet, SQLite, and Markdown.
  • MCP server — expose the deep_dive tool to Claude/Codex and any MCP-compatible agent.
  • Nitter rotation — falls through a list of Nitter instances until one responds.

Architecture

                          ┌──────────────────────────────────────┐
                          │            Agent / CLI               │
                          │   (MCP client or `deepdive` command) │
                          └───────────────────┬──────────────────┘
                                              │  topic + options
                                              ▼
                          ┌──────────────────────────────────────┐
                          │           deepdive.engine            │
                          │   run_deep_dive(topic, sources, ...) │
                          └───┬──────────┬──────────┬─────────┬──┘
                              │          │          │         │
                              │          │          │         │
                ┌─────────────▼──┐  ┌────▼─────┐  ┌──▼──────┐ │
                │   llm.client   │  │  sources │  │ sources │ │
                │ generate_key   │  │  web.py  │  │ reddit  │ │
                │   words(topic) │  └────┬─────┘  │  .py    │ │
                └───────┬────────┘       │        └──┬──────┘ │
                        │                │           │        │
                        │    ┌───────────▼─────┐   ┌─▼────────▼─┐
                        │    │ x_twitter.py     │   │ youtube.py  │
                        │    │ (Nitter rotation)│   │ +transcripts│
                        │    └──────────────────┘   └────────────┘
                        │
                        │  all scraped data (lists of dicts)
                        ▼
              ┌───────────────────────┐
              │   llm.synthesizer     │  create_report(data, topic)
              │  chunked LLM synthesis│
              └───────────┬───────────┘
                          ▼
              ┌───────────────────────┐
              │   utils.helpers        │  write_output(data, path, format)
              │  JSON/CSV/Parquet/     │
              │  SQLite/Markdown       │
              └───────────────────────┘

Flow:

  1. engine.run_deep_dive(topic, sources, output_format) is the single entry point.
  2. llm.client.generate_keywords(topic) produces targeted search terms.
  3. Every selected scraper runs concurrently inside asyncio.gather(), each returning a list[dict] shaped as {title, url, content/snippet, author, score, source, ...}.
  4. llm.synthesizer.create_report(data, topic) merges everything (chunking large payloads) into a structured deep-dive report via the local LLM.
  5. utils.helpers.write_output(...) persists the result in the requested format.

Installation

# 1. Clone / enter the repo
cd Deepdive-goblin-scrape

# 2. Create a virtual environment (Python 3.12+)
python3.12 -m venv .venv
source .venv/bin/activate

# 3. Install the package (editable, with dev + parquet extras)
pip install -e ".[dev,parquet]"

# 4. Install Playwright browsers
playwright install chromium
playwright install-deps chromium   # system dependencies (optional but recommended)

If you only need the default formats you can skip parquet: pip install -e .


Configuration

Configuration is loaded by deepdive/config.py (Pydantic BaseSettings) from, in order of precedence: CLI flags > environment variables > defaults.

Key settings (all overridable via env, prefixed DEEPDIVE_):

Setting Env var Default
local_llm_url DEEPDIVE_LOCAL_LLM_URL http://localhost:8888/v1
local_api_key DEEPDIVE_LOCAL_API_KEY from ~/.mrboom/.local_api_key (else "local")
nitter_instances DEEPDIVE_NITTER_INSTANCES https://nitter.privacydev.net, https://nitter.poast.org
reddit_user_agent DEEPDIVE_REDDIT_USER_AGENT DeepDive/1.0
reddit_client_id DEEPDIVE_REDDIT_CLIENT_ID ""
reddit_client_secret DEEPDIVE_REDDIT_CLIENT_SECRET ""
reddit_username DEEPDIVE_REDDIT_USERNAME ""
reddit_password DEEPDIVE_REDDIT_PASSWORD ""
youtube_default_language DEEPDIVE_YOUTUBE_DEFAULT_LANGUAGE en
max_concurrency DEEPDIVE_MAX_CONCURRENCY 5
request_delay DEEPDIVE_REQUEST_DELAY 1.5
proxies DEEPDIVE_PROXIES {}
headers DEEPDIVE_HEADERS realistic browser defaults

Environment-only settings can also be placed in a .env file at the repo root (pip install python-dotenv not required — pydantic-settings reads .env natively).

Reddit requires API credentials to do anything useful (guest mode falls back gracefully). Create an app at https://www.reddit.com/prefs/apps and export:

export DEEPDIVE_REDDIT_CLIENT_ID=...
export DEEPDIVE_REDDIT_CLIENT_SECRET=...
export DEEPDIVE_REDDIT_USERNAME=...
export DEEPDIVE_REDDIT_PASSWORD=...

CLI Usage

The CLI is installed as deepdive (Typer).

# Basic deep dive, print to stdout
deepdive "AI in healthcare"

# Write a Markdown report
deepdive "AI in healthcare" --format markdown --output report.md

# JSON export
deepdive "quantum computing breakthroughs" --format json --output report.json

# CSV export
deepdive "best robotics projects for beginners" --format csv --output report.csv

# Only scrape a subset of sources
deepdive "AI agents" --sources web,reddit,youtube

# Only generate keywords (no scraping, no synthesis)
deepdive "AI agents" --keywords-only

# Tune concurrency / delay
deepdive "AI agents" --concurrency 10 --delay 0.5

# Use a proxy for outbound requests
deepdive "AI agents" --proxy "http://user:pass@proxy:8080"

# Override Nitter instances
deepdive "AI agents" --nitter-instance "https://nitter.example.com"

# Verbose logging
deepdive "AI agents" --verbose

CLI reference

deepdive TOPIC [--output PATH] [--format json|csv|parquet|sqlite|markdown]
                [--sources web,x-twitter,reddit,youtube] [--concurrency INT]
                [--delay FLOAT] [--proxy URL] [--nitter-instance URL]
                [--keywords-only] [--verbose]

MCP Integration

The MCP server lives in deepdive/mcp_server.py. It exposes a single tool:

deep_dive(topic: str, sources: list[str] | None, output_format: Literal[
    "json", "csv", "parquet", "sqlite", "markdown"
])

The tool returns a structured result:

{
  "executive_summary": "...",
  "web_insights": [...],
  "x_twitter_sentiment": [...],
  "reddit_highlights": [...],
  "youtube_breakdown": [...],
  "deep_analysis": "...",
  "metadata": {"topic": "...", "sources": [...], "generated_at": "...", "latency_ms": ...}
}

Register with Claude Desktop

Edit claude_desktop_config.json:

{
  "mcpServers": {
    "deepdive": {
      "command": "deepdive-mcp",
      "args": []
    }
  }
}

deepdive-mcp is a console entry point that runs the server over stdio (see deepdive/mcp_server.py). You can also run it manually:

deepdive-mcp

Register with Codex / other MCP clients

Any MCP client that can run a stdio subprocess works. See examples/config.yaml for a ready-made config, and examples/queries.md for sample deep-dive prompts and expected outputs.

Once connected, just ask the agent:

"Deep dive into the latest breakthroughs in quantum computing."

The agent will call the deep_dive tool and receive a synthesized report.


Export Formats

utils/helpers.write_output supports five formats:

Format Notes
json Pretty-printed JSON of the full report structure.
csv Flat CSV — one row per source result (via json_normalize).
parquet Pandas/pyarrow required (pip install -e ".[parquet]").
sqlite Creates a .db with a results table and optional report table.
markdown Readable human report with sections per source.

Development

# Run the test suite
pytest

# Lint
ruff check .
ruff format --check .

# Format
ruff format .

Adding a new source

  1. Create deepdive/sources/<name>.py with async def scrape_<name>(topic, keywords, config) -> list[dict].
  2. Each result dict must include at least title, url, and source; add extra keys as appropriate (content, author, score, ...).
  3. Register the new source in engine.py (SOURCE_HANDLERS / ALL_SOURCES) and add it to the --sources choices in cli.py.

FAQ / Troubleshooting

  • The local LLM is not running. The engine logs a warning and proceeds with a heuristic fallback (raw keyword splitting + template-based synthesis) so scraping still works. Start your Qwen3.6/OpenAI-compatible server at http://localhost:8888/v1 for full quality.
  • Reddit returns nothing. Guest browsing to Reddit is heavily rate limited; provide reddit_client_id/reddit_client_secret (script app) for reliable access.
  • Nitter instances are down. The scraper rotates through all configured instances and degrades gracefully if none respond. Add more instances via DEEPDIVE_NITTER_INSTANCES.
  • Playwright browser not installed. Run playwright install chromium.
  • Parquet export fails. Install the parquet extra: pip install -e ".[parquet]".

License

MIT

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages