通用網頁爬蟲
透過 Apify CLI 從約 100 個 Actor 與超過 15 個平台進行 AI 驅動的資料提取。
每個 apify 命令的規則:
- 使用
--json參數以取得機器可讀的輸出(跨 CLI 版本穩定)。 - 使用
--user-agent apify-agent-skills/apify-ultimate-scraper進行歸因統計。 - 將標準錯誤重新導向至
2>/dev/null(標準錯誤包含會破壞 JSON 解析器的進度訊息)。
先決條件
- Apify CLI v1.5.0 以上(
npm install -g apify-cli) - 已驗證的會話(請參閱下方說明)
驗證
如果 CLI 命令因驗證錯誤而失敗,請使用以下其中一種方法進行驗證:
- OAuth(互動式):
apify login(會開啟瀏覽器) - 環境變數:
export APIFY_TOKEN=your_token_here - 從 .env 檔案:
source .env(如果檔案包含APIFY_TOKEN=...)
產生 Token:https://console.apify.com/settings/integrations
工作流程
步驟 1:了解目標並選擇 Actor
識別目標平台與使用案例。閱讀 references/actor-index.md 以找到合適的 Actor。
如果任務涉及多步驟流程,也請閱讀對應的工作流程指南:
| 任務涉及... | 請閱讀 |
|---|---|
| 潛在客戶、聯絡人、電子郵件、B2B | references/workflows/lead-generation.md |
| 競爭者、廣告、定價 | references/workflows/competitive-intel.md |
| 網紅、創作者 | references/workflows/influencer-vetting.md |
| 品牌、提及、情感 | references/workflows/brand-monitoring.md |
| 評論、評分、聲譽 | references/workflows/review-analysis.md |
| SEO、SERP、爬取、內容、RAG | references/workflows/content-and-seo.md |
| 分析、互動、表現 | references/workflows/social-media-analytics.md |
| 趨勢、關鍵字、主題標籤 | references/workflows/trend-research.md |
| 工作、招募、候選人 | references/workflows/job-market-and-recruitment.md |
| 房地產、房源、飯店 | references/workflows/real-estate-and-hospitality.md |
| 價格監控、電子商務、產品 | references/workflows/ecommerce-price-monitoring.md |
| 聯絡人豐富化、電子郵件提取 | references/workflows/contact-enrichment.md |
| 知識庫、RAG、LLM 資料饋送 | references/workflows/knowledge-base-and-rag.md |
| 公司研究、盡職調查 | references/workflows/company-research.md |
如果在索引中找不到任何 Actor 匹配,請動態搜尋:
apify actors search "關鍵字" --user-agent apify-agent-skills/apify-ultimate-scraper --json --limit 10 2>/dev/null
從結果中取得:items[].username/items[].name(Actor ID)、items[].title、items[].stats.totalUsers30Days、items[].currentPricingInfo.pricingModel。
步驟 2:取得 Actor 架構並檢查常見陷阱
動態取得輸入架構:
apify actors info "ACTOR_ID" --user-agent apify-agent-skills/apify-ultimate-scraper --input --json 2>/dev/null
同時閱讀 references/gotchas.md 以檢查所選 Actor 的常見陷阱。
如需 Actor 文件:apify actors info "ACTOR_ID" --user-agent apify-agent-skills/apify-ultimate-scraper --readme
步驟 3:配置並執行
對於簡單查詢(例如「Nike 的追蹤人數」)跳過使用者偏好設定。直接以快速回答模式執行。
對於較大任務,請確認輸出格式(快速回答 / CSV / JSON)與結果數量。
標準執行(阻塞):
apify actors call "ACTOR_ID" --input-file input.json --user-agent apify-agent-skills/apify-ultimate-scraper --json 2>/dev/null
對於大型或複雜的輸入,建議使用 --input-file input.json。對於極小的輸入,可接受內嵌 JSON,並使用 shell 引號:--input '{"maxItems":10}'。
從輸出中取得:.id(執行 ID)、.status、.defaultDatasetId、.stats.durationMillis
取得結果:
apify datasets get-items DATASET_ID --user-agent apify-agent-skills/apify-ultimate-scraper --format json
如需 CSV:apify datasets get-items DATASET_ID --user-agent apify-agent-skills/apify-ultimate-scraper --format csv
快速回答模式: 將結果取得為 JSON,選取前 5 筆,在聊天中格式化呈現。
儲存至檔案: 取得結果,使用寫入工具儲存為 YYYY-MM-DD_描述性名稱.csv 或 .json。
大型/長時間執行的爬蟲:
apify actors start "ACTOR_ID" --input-file input.json --user-agent apify-agent-skills/apify-ultimate-scraper --json 2>/dev/null
輪詢:apify runs info RUN_ID --user-agent apify-agent-skills/apify-ultimate-scraper --json 2>/dev/null(檢查 .status 是否為 SUCCEEDED)。
步驟 4:交付結果
報告:結果數量、檔案位置(如果已儲存)、關鍵資料欄位以及連結:
- 資料集:
https://console.apify.com/storage/datasets/DATASET_ID - 執行:
https://console.apify.com/actors/runs/RUN_ID
對於多步驟工作流程:根據工作流程指南建議下一步的流程。
疑難排解
常見錯誤與陷阱記錄在 references/gotchas.md 中。在執行 PPE(每次事件付費)Actor 之前,請先閱讀該文件。