通用网页爬虫 是做什么的?
通过Apify CLI从100多个Actor中提取数据的AI驱动工具,覆盖15+平台。
每条 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=...)
生成令牌:https://console.apify.com/settings/integrations
工作流程
步骤1:理解目标并选择Actor
确定目标平台和用例。阅读 references/actor-index.md 以找到合适的Actor。
如果任务涉及多步骤管道,也请阅读匹配的工作流指南:
| 任务涉及... | 阅读 |
|---|---|
| 潜在客户、联系方式、电子邮件、B2B | references/workflows/lead-generation.md |
| 竞争对手、广告、定价 | references/workflows/competitive-intel.md |
| KOL、创作者 | 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条,在聊天中格式化呈现。
保存到文件: 获取结果,使用Write工具保存为 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之前请阅读该文件。