⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.
feat: add BrightData four-tier web scraping skill
Daniel Miessler3066fce84a33
diff --git a/README.md b/README.mdindex ac0de01f..e3727966 100644--- a/README.md+++ b/README.md@@ -148,6 +148,7 @@ claude-codeExplore example skills in `.claude/skills/`:+- **`brightdata/`** - Four-tier progressive web scraping with automatic fallback (WebFetch → cURL → Playwright → Bright Data MCP)- **`fabric/`** - Integration with Fabric pattern system (242+ AI patterns)- **`research/`** - Multi-source research workflows- **`create-skill/`** - Templates for creating new skillsdiff --git a/skills/brightdata/README.md b/skills/brightdata/README.mdnew file mode 100644index 00000000..7ecb3ac7--- /dev/null+++ b/skills/brightdata/README.md@@ -0,0 +1,170 @@+# BrightData Four-Tier Web Scraping++Progressive escalation strategy for reliable URL content retrieval with automatic fallback.++## Overview++This skill implements a four-tier progressive web scraping system that automatically escalates through increasingly powerful methods until it succeeds. It starts with fast, free tools and only uses paid services when necessary.++### The Four Tiers++1. **Tier 1: WebFetch** - Built-in Claude Code tool (~2-5 seconds, free)+2. **Tier 2: cURL + Headers** - Chrome-like browser headers (~3-7 seconds, free)+3. **Tier 3: Browser Automation** - Full Playwright execution (~10-20 seconds, free)+4. **Tier 4: Bright Data MCP** - Professional scraping service (~5-15 seconds, paid)++The system automatically tries each tier in order, only escalating when the previous tier fails.++## Setup Requirements++### 1. Bright Data API Key++To use Tier 4 (Bright Data MCP), you need a Bright Data account and API key:++1. **Create Account**: Sign up at [https://brightdata.com](https://brightdata.com)+2. **Get API Key**:+ - Navigate to your account settings+ - Go to the API section+ - Generate a new API key+ - Full documentation: [Bright Data API Documentation](https://docs.brightdata.com/api-reference/web-scraper/introduction)++3. **Configure MCP**:+ - Add the Bright Data MCP to your Claude Code configuration+ - Provide your API key when configuring the MCP server+ - The MCP handles authentication automatically++### 2. Browser Automation (Optional)++For Tier 3, you need Playwright installed:++```bash+# Install Playwright+npm install -D playwright+# or+bun add -d playwright++# Install browsers+npx playwright install+```++## Usage++Once configured, simply ask Claude Code to scrape URLs:++```+"Scrape this URL"+"Get content from https://example.com"+"Can't access this site - help me fetch it"+"Use Bright Data to fetch https://difficult-site.com"+```++The skill automatically:+- Routes your request to the four-tier workflow+- Tries each tier until success+- Returns content in markdown format+- Reports which tier succeeded++## Cost Optimization++The progressive escalation strategy minimizes costs:++- **Most sites (60-70%)**: Succeed at Tier 1 or 2 (free)+- **JavaScript-heavy sites**: Escalate to Tier 3 (free, but slower)+- **Protected sites**: Use Tier 4 only when necessary (minimal cost)++**Real-world costs**: Over 3 weeks of heavy usage with tons of queries, total Bright Data costs were $0.31 (averaging $0.01 per day).++## When Each Tier Is Used++### Tier 1 (WebFetch)+- Simple public websites+- No bot detection+- No JavaScript requirements+- **Success rate**: ~40%++### Tier 2 (cURL + Headers)+- Basic user-agent checking+- Simple header validation+- Static content sites+- **Success rate**: ~20-30%++### Tier 3 (Browser Automation)+- JavaScript-heavy sites (React, Vue, Angular)+- Single-page applications (SPAs)+- Dynamic content loading+- Cookie/session requirements+- **Success rate**: ~20-25%++### Tier 4 (Bright Data)+- CAPTCHA challenges+- Advanced bot detection+- Residential IP requirements+- Aggressive rate limiting+- **Success rate**: ~95%+++## Examples++### Example 1: Simple Site (Tier 1)+```+You: "Scrape https://example.com"++Kai: Successfully retrieved content using Tier 1 (WebFetch)+ [Content in markdown...]+```++### Example 2: JavaScript Site (Tier 3)+```+You: "Get content from https://spa-site.com"++Kai: Tier 1 failed (empty content)+ Tier 2 failed (JavaScript required)+ Successfully retrieved content using Tier 3 (Browser Automation)+ [Content in markdown...]+```++### Example 3: Protected Site (Tier 4)+```+You: "Scrape https://protected-site.com"++Kai: Tier 1 failed (blocked)+ Tier 2 failed (bot detection)+ Tier 3 failed (CAPTCHA)+ Successfully retrieved content using Tier 4 (Bright Data)+ [Content in markdown...]+```++## Skill Structure++```+brightdata/+├── SKILL.md # Skill definition and routing+├── README.md # This file+└── workflows/+ └── four-tier-scrape.md # Main workflow implementation+```++## Ethical Use++This system is designed exclusively for scraping publicly available data. It should not be used to:+- Bypass authentication or access restricted content+- Violate terms of service+- Access private or protected data+- Perform any illegal scraping activities++Always respect robots.txt and website terms of service.++## Related Resources++- **Blog Post**: [Progressive Web Scraping: Four-Tier System](https://danielmiessler.com/blog/progressive-web-scraping-four-tier-system)+- **PAI Repository**: [github.com/danielmiessler/PAI](https://github.com/danielmiessler/PAI)+- **Bright Data Documentation**: [docs.brightdata.com](https://docs.brightdata.com)++## Support++Questions or improvements?+- Email: [email protected]+- X/Twitter: @danielmiessler++---++**AIL Tier Level 5** (Highest AI Involvement) - Daniel's idea completely implemented by Kai.diff --git a/skills/brightdata/SKILL.md b/skills/brightdata/SKILL.mdnew file mode 100644index 00000000..75592083--- /dev/null+++ b/skills/brightdata/SKILL.md@@ -0,0 +1,155 @@+---+name: brightdata+description: |+ Progressive four-tier URL content scraping with automatic fallback strategy.++ USE WHEN user says "scrape this URL", "fetch this page", "get content from",+ "can't access this site", "use Bright Data", "pull content from URL",+ or needs to retrieve web content that may have bot detection or access restrictions.+---++## Workflow Routing (SYSTEM PROMPT)++**CRITICAL: This workflow implements progressive escalation for URL content retrieval.**++**When user requests scraping/fetching URL content:**+Examples: "scrape this URL", "fetch this page", "get content from [URL]", "pull content from this site", "retrieve [URL]", "can't access this site", "this site is blocking me", "use Bright Data to fetch"+→ **READ:** ~/.claude/skills/brightdata/workflows/four-tier-scrape.md+→ **EXECUTE:** Four-tier progressive scraping workflow (WebFetch → Curl → Browser Automation → Bright Data MCP)++---++## When to Activate This Skill++### Direct Scraping Requests (Categories 1-4)+- "scrape this URL", "scrape [URL]", "scrape this page"+- "fetch this URL", "fetch [URL]", "fetch this page", "fetch content from"+- "pull content from [URL]", "pull this page", "pull from this site"+- "get content from [URL]", "retrieve [URL]", "retrieve this page"+- "do scraping on [URL]", "run scraper on [URL]"+- "basic scrape", "quick scrape", "simple fetch"+- "comprehensive scrape", "deep scrape", "full content extraction"++### Access & Bot Detection Issues (Categories 5-7)+- "can't access this site", "site is blocking me", "getting blocked"+- "bot detection", "CAPTCHA", "access denied", "403 error"+- "need to bypass bot detection", "get around blocking"+- "this URL won't load", "can't fetch this page"+- "use Bright Data", "use the scraper", "use advanced scraping"++### Result-Oriented Requests (Category 8)+- "get me the content from [URL]"+- "extract text from [URL]"+- "download this page content"+- "convert [URL] to markdown"+- "need the HTML from this site"++### Use Case Indicators+- User needs web content for research or analysis+- Standard methods (WebFetch) are failing+- Site has bot detection or rate limiting+- Need reliable content extraction+- Converting web pages to structured format (markdown)++---++## Core Capabilities++**Progressive Escalation Strategy:**+1. **Tier 1: WebFetch** - Fast, simple, built-in Claude Code tool+2. **Tier 2: Customized Curl** - Chrome-like browser headers to bypass basic bot detection+3. **Tier 3: Browser Automation** - Full browser automation using Playwright for JavaScript-heavy sites+4. **Tier 4: Bright Data MCP** - Professional scraping service that handles CAPTCHA and advanced bot detection++**Key Features:**+- Automatic fallback between tiers+- Preserves content in markdown format+- Handles bot detection and CAPTCHA+- Works with any URL+- Efficient resource usage (only escalates when needed)++---++## Workflow Overview++**four-tier-scrape.md** - Complete URL content scraping with four-tier fallback strategy+- **When to use:** Any URL content retrieval request+- **Process:** Start with WebFetch → If fails, use curl with Chrome headers → If fails, use Browser Automation → If fails, use Bright Data MCP+- **Output:** URL content in markdown format++---++## Extended Context++**Integration Points:**+- **WebFetch Tool** - Built-in Claude Code tool for basic URL fetching+- **Bash Tool** - For executing curl commands with custom headers+- **Browser Automation** - Playwright-based browser automation for JavaScript rendering+- **Bright Data MCP** - `mcp__Brightdata__scrape_as_markdown` for advanced scraping++**When Each Tier Is Used:**+- **Tier 1 (WebFetch):** Simple sites, public content, no bot detection+- **Tier 2 (Curl):** Sites with basic user-agent checking, simple bot detection+- **Tier 3 (Browser Automation):** Sites requiring JavaScript execution, dynamic content loading+- **Tier 4 (Bright Data):** Sites with CAPTCHA, advanced bot detection, residential proxy requirements++**Configuration:**+No configuration required - all tools are available by default in Claude Code++---++## Examples++**Example 1: Simple Public Website**++User: "Scrape https://example.com"++Skill Response:+1. Routes to three-tier-scrape.md+2. Attempts Tier 1 (WebFetch)+3. Success → Returns content in markdown+4. Total time: <5 seconds++**Example 2: Site with JavaScript Requirements**++User: "Can't access this site https://dynamic-site.com"++Skill Response:+1. Routes to four-tier-scrape.md+2. Attempts Tier 1 (WebFetch) → Fails (blocked)+3. Attempts Tier 2 (Curl with Chrome headers) → Fails (JavaScript required)+4. Attempts Tier 3 (Browser Automation) → Success+5. Returns content in markdown+6. Total time: ~15-20 seconds++**Example 3: Site with Advanced Bot Detection**++User: "Scrape https://protected-site.com"++Skill Response:+1. Routes to four-tier-scrape.md+2. Attempts Tier 1 (WebFetch) → Fails (blocked)+3. Attempts Tier 2 (Curl) → Fails (advanced detection)+4. Attempts Tier 3 (Browser Automation) → Fails (CAPTCHA)+5. Attempts Tier 4 (Bright Data MCP) → Success+6. Returns content in markdown+7. Total time: ~30-40 seconds++**Example 4: Explicit Bright Data Request**++User: "Use Bright Data to fetch https://difficult-site.com"++Skill Response:+1. Routes to four-tier-scrape.md+2. User explicitly requested Bright Data+3. Goes directly to Tier 4 (Bright Data MCP) → Success+4. Returns content in markdown+5. Total time: ~5-10 seconds++---++**Related Documentation:**+- `~/.claude/skills/CORE/SKILL-STRUCTURE-AND-ROUTING.md` - Canonical structure guide+- `~/.claude/skills/CORE/CONSTITUTION.md` - Overall Kai philosophy++**Last Updated:** 2025-11-23diff --git a/skills/brightdata/workflows/four-tier-scrape.md b/skills/brightdata/workflows/four-tier-scrape.mdnew file mode 100644index 00000000..3b1fb49f--- /dev/null+++ b/skills/brightdata/workflows/four-tier-scrape.md@@ -0,0 +1,390 @@+# Four-Tier URL Content Scraping++**Purpose:** Progressive escalation strategy to retrieve URL content using four fallback tiers++**When to Use:**+- User requests scraping or fetching content from any URL+- Standard methods are failing or blocked+- Site has bot detection or access restrictions+- Need reliable content extraction in markdown format++**Prerequisites:**+- URL to scrape (provided by user)+- WebFetch tool (built-in)+- Bash tool for curl commands+- Browser automation capability (Playwright)+- Bright Data MCP available++---++## Workflow Steps++### Step 1: Tier 1 - WebFetch (Fast & Simple)++**Description:** Attempt to fetch URL using Claude Code's built-in WebFetch tool++**Actions:**+```+Use WebFetch tool with:+- URL: [user-provided URL]+- Prompt: "Extract all content from this page and convert to markdown"+```++**Expected Outcomes:**+- **Success:** Content retrieved in markdown format → Skip to Step 4 (Output)+- **Failure:** WebFetch blocked, timeout, or error → Proceed to Step 2 (Tier 2)++**Typical Success Cases:**+- Public websites without bot detection+- Simple content sites+- Sites with permissive access policies++**Typical Failure Cases:**+- Sites with user-agent filtering+- Sites with basic bot detection+- Sites requiring specific headers++---++### Step 2: Tier 2 - Customized Curl (Chrome-like Headers)++**Description:** Use curl with comprehensive Chrome browser headers to bypass basic bot detection++**Actions:**+```bash+curl -L -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" \+ -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8" \+ -H "Accept-Language: en-US,en;q=0.9" \+ -H "Accept-Encoding: gzip, deflate, br" \+ -H "DNT: 1" \+ -H "Connection: keep-alive" \+ -H "Upgrade-Insecure-Requests: 1" \+ -H "Sec-Fetch-Dest: document" \+ -H "Sec-Fetch-Mode: navigate" \+ -H "Sec-Fetch-Site: none" \+ -H "Sec-Fetch-User: ?1" \+ -H "Cache-Control: max-age=0" \+ --compressed \+ "[URL]"+```++**Header Explanation:**+- **User-Agent:** Latest Chrome on macOS (most common, least suspicious)+- **Accept headers:** Legitimate browser accept patterns+- **Sec-Fetch-* headers:** Chrome's security headers (critical for bypassing detection)+- **DNT:** Do Not Track (common privacy setting)+- **--compressed:** Handle gzip/br encoding like real browsers++**Expected Outcomes:**+- **Success:** HTML content retrieved → Convert to markdown → Skip to Step 5 (Output)+- **Failure:** Still blocked, CAPTCHA, or JavaScript required → Proceed to Step 3 (Tier 3)++**Typical Success Cases:**+- Sites with basic user-agent checking+- Sites with simple header validation+- Sites without JavaScript rendering requirements++**Typical Failure Cases:**+- Sites with CAPTCHA+- Sites requiring JavaScript execution+- Sites with advanced fingerprinting+- Sites with IP-based rate limiting++---++### Step 3: Tier 3 - Browser Automation (Playwright)++**Description:** Use full browser automation with Playwright to handle JavaScript-heavy sites++**Actions:**+```typescript+// Use browser automation to navigate to URL and extract content+// Playwright provides full Chrome/Firefox browser automation+// Handles JavaScript rendering, dynamic content, and complex interactions+```++**What Browser Automation Provides:**+- Real browser execution (Chrome/Firefox)+- Full JavaScript rendering and execution+- DOM manipulation and dynamic content loading+- Cookie/session handling+- Screenshot and PDF capabilities+- Network request interception+- Proper browser fingerprinting++**Expected Outcomes:**+- **Success:** Content extracted from fully rendered page → Convert to markdown → Skip to Step 5 (Output)+- **Failure:** CAPTCHA or advanced bot detection → Proceed to Step 4 (Tier 4)++**Typical Success Cases:**+- Single-page applications (SPAs)+- Sites with heavy JavaScript frameworks (React, Vue, Angular)+- Sites with dynamic content loading+- Sites requiring cookies/sessions+- Sites with complex DOM structures++**Typical Failure Cases:**+- Sites with CAPTCHA challenges+- Sites with advanced bot detection that fingerprint browser automation+- Sites requiring residential IP addresses+- Sites with aggressive rate limiting based on datacenter IPs++---++### Step 4: Tier 4 - Bright Data MCP (Professional Scraping)++**Description:** Use Bright Data MCP's professional scraping service with bot detection bypass++**Actions:**+```+Use mcp__Brightdata__scrape_as_markdown tool with:+- URL: [user-provided URL]+```++**What Bright Data Provides:**+- Residential proxy network (real IP addresses)+- Automatic CAPTCHA solving+- JavaScript rendering (headless browser)+- Anti-bot detection bypass+- Automatic retry logic+- Content extraction and markdown conversion++**Expected Outcomes:**+- **Success:** Content retrieved in markdown format → Proceed to Step 5 (Output)+- **Failure:** Extremely rare - site may be completely inaccessible or down++**Typical Success Cases:**+- Sites with CAPTCHA challenges+- Sites with advanced bot detection and fingerprinting+- Sites requiring residential IP addresses+- Sites with aggressive rate limiting+- Any site that blocked Tiers 1, 2, and 3++**Typical Failure Cases:**+- Site is completely down+- Site requires authentication (login)+- Site has legal restrictions (e.g., paywall, geographic restrictions)++---++### Step 5: Output & Verification++**Description:** Present retrieved content to user with tier information++**Actions:**+- Present content in markdown format+- Indicate which tier was successful+- Provide any warnings or notes about content quality++**Verification:**+- Content is readable and properly formatted+- Content matches expected URL+- No major sections missing++**Example Output:**+```markdown+Successfully retrieved content from [URL] using Tier [1/2/3/4]++[Content in markdown format...]+```++---++## Outputs++**Primary Output:**+- URL content in markdown format+- Includes title, headers, paragraphs, links, images (as markdown)++**Metadata:**+- Which tier was successful+- Any warnings or notes+- Execution time++**Where outputs are stored:**+- Returned directly to user in conversation+- No persistent storage (unless user requests it)++---++## Decision Logic++```+START+ ↓+Attempt Tier 1 (WebFetch)+ ↓+Success? → Yes → Return content ✓+ ↓+ No+ ↓+Attempt Tier 2 (Curl + Chrome Headers)+ ↓+Success? → Yes → Return content ✓+ ↓+ No+ ↓+Attempt Tier 3 (Browser Automation)+ ↓+Success? → Yes → Return content ✓+ ↓+ No+ ↓+Attempt Tier 4 (Bright Data MCP)+ ↓+Success? → Yes → Return content ✓+ ↓+ No+ ↓+Report failure + suggest alternatives+```++---++## Error Handling++**If Tier 1 Fails:**+- Log failure reason (blocked, timeout, error)+- Automatically proceed to Tier 2+- No user intervention required++**If Tier 2 Fails:**+- Log failure reason+- Automatically proceed to Tier 3+- No user intervention required++**If Tier 3 Fails:**+- Log failure reason+- Automatically proceed to Tier 4+- No user intervention required++**If Tier 4 Fails:**+- Report to user that site is inaccessible+- Suggest alternatives:+ - Check if URL is correct+ - Check if site requires authentication+ - Check if site has geographic restrictions+ - Try accessing manually in browser to verify site is up++---++## Optimization Notes++**When to Skip Tiers:**+- If user explicitly requests "use Bright Data" → Skip directly to Tier 4+- If user explicitly requests "use browser" → Skip to Tier 3+- If previous scrape of same domain failed at Tier 1 → Start at Tier 2+- If URL is known SPA or JavaScript-heavy → Consider starting at Tier 3+- If URL is known difficult site with CAPTCHA → Consider starting at Tier 4++**Cost Considerations:**+- Tier 1: Free (built-in)+- Tier 2: Free (built-in)+- Tier 3: Free (local browser automation)+- Tier 4: Uses Bright Data credits (minimal cost per scrape)+- Always try cheaper tiers first unless user specifies otherwise++**Performance:**+- Tier 1: ~2-5 seconds+- Tier 2: ~3-7 seconds+- Tier 3: ~10-20 seconds+- Tier 4: ~5-15 seconds+- Total worst-case: ~40 seconds for all four attempts++---++## Related Workflows++- None (this is the primary workflow for brightdata skill)++**Future Enhancements:**+- Add caching layer to avoid re-scraping same URLs+- Add batch scraping for multiple URLs+- Add domain-specific optimizations (known difficult sites)+- Add custom header profiles for different site types++---++## Examples++**Example 1: Public Site (Tier 1 Success)**++Input: https://example.com++Process:+1. Attempt Tier 1 (WebFetch)+2. Success in 3 seconds+3. Return content++Output:+```markdown+Successfully retrieved content from https://example.com using Tier 1 (WebFetch)++# Example Domain++This domain is for use in illustrative examples...+```++**Example 2: JavaScript-Heavy Site (Tier 3 Success)**++Input: https://spa-site.com++Process:+1. Attempt Tier 1 (WebFetch) → Blocked (403)+2. Attempt Tier 2 (Curl) → Returns empty (JavaScript required)+3. Attempt Tier 3 (Browser Automation) → Success in 15 seconds+4. Return content++Output:+```markdown+Successfully retrieved content from https://spa-site.com using Tier 3 (Browser Automation)++Note: This site requires JavaScript rendering. Content was retrieved using Playwright.++# SPA Site Content++[Content retrieved successfully...]+```++**Example 3: Protected Site with CAPTCHA (Tier 4 Success)**++Input: https://protected-site.com++Process:+1. Attempt Tier 1 (WebFetch) → Blocked (403)+2. Attempt Tier 2 (Curl) → Blocked (bot detection)+3. Attempt Tier 3 (Browser Automation) → Blocked (CAPTCHA)+4. Attempt Tier 4 (Bright Data) → Success in 12 seconds+5. Return content++Output:+```markdown+Successfully retrieved content from https://protected-site.com using Tier 4 (Bright Data MCP)++Note: This site has advanced bot detection and CAPTCHA. Content was retrieved using professional scraping service.++# Protected Site Content++[Content retrieved successfully...]+```++**Example 4: Explicit Bright Data Request**++Input: "Use Bright Data to fetch https://any-site.com"++Process:+1. User explicitly requested Bright Data+2. Skip directly to Tier 4+3. Success in 8 seconds+4. Return content++Output:+```markdown+Retrieved content from https://any-site.com using Tier 4 (Bright Data MCP) as requested++[Content...]+```++---++**Last Updated:** 2025-11-23