Multi-Forum Scraping Architecture — API vs Playwright

Domain: devops · Evidence E0 — Contributor self-reported
scrapingplaywrightapiforumautomationdata-collection

Summary

Scraping multiple technical forums requires different approaches per site. Some have APIs, some require browser automation, some are behind anti-bot protection.…

Problem

Scraping multiple technical forums requires different approaches per site. Some have APIs, some require browser automation, some are behind anti-bot protection. Need a systematic way to choose and implement.

Root Cause

Each forum has different:

Solution

Decision Tree

Is there an API?
  ├─ Yes → Use API (JSON, structured, reliable)
  │         Examples: HN Algolia, Dev.to REST, GitHub API
  └─ No → Is the site behind anti-bot?
              ├─ Yes → Need browser automation (Playwright)
              │         Examples: robot-forum.com (WoltLab)
              └─ No → Try curl first, fall back to Playwright
                        Examples: Juejin, SegmentFault

Implementation Patterns

Pattern 1: API-Based (Preferred)

# HN Algolia API
import urllib.request, json
url = "https://hn.algolia.com/api/v1/search?query=MCP&tags=story&hitsPerPage=10"
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req, timeout=10) as resp:
    data = json.loads(resp.read())
    for hit in data["hits"]:
        print(f"[{hit['points']}↑] {hit['title']}")

Pros: Fast, structured, no browser overhead Cons: Not all sites have APIs

Pattern 2: Playwright-Based

const { chromium } = require('playwright');
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
await page.waitForTimeout(3000);  // Wait for JS rendering
const text = await page.evaluate(() => {
    const main = document.querySelector('#content, main');
    return main ? main.innerText : '';
});

Pros: Works on any site, handles JS rendering Cons: Slower, needs browser binary, site-specific selectors

Pattern 3: Hybrid (API + Playwright)

Use API for listing/searching, Playwright for reading full content.

API → Get list of URLs → Playwright → Read each URL's content

Site-Specific Findings

SiteMethodGotcha
HNAlgolia APIUse tags=story filter
Dev.toREST APINeeds User-Agent header (403 without)
robot-forum.comPlaywrightWoltLab ol.wbbThread selector, data-is-done for resolved
JuejinPlaywrightSearch requires login for full results
Reddit❌ BlockedGFW SNI block, needs proxy
StackOverflow❌ 403Anti-bot

Rate Limiting

Between page loads:  2-3 seconds
Between API calls:   1 second
Per-site daily limit: ~500 pages (be respectful)

Verification

echo "Lesson: Multi-Forum Scraping Architecture — API vs Playwri"
wc -l lessons/contrib/multi-forum-scraping-architecture.md

Expected Output:

Lesson: Multi-Forum Scraping Architecture — API vs Playwri
# (line count)

Notes

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons