关于 apify-scrapers
一组通过 Apify actors 抓取公开社交、商业和广告数据的 Python 脚本与指南,适用于研究人员和营销团队。项目提供按平台划分的命令,并涵盖趋势分析、潜在客户开发和竞争研究流程。
主要功能
- 01抓取社交平台帖子和主页
- 02收集 Google Maps 商家及评价数据
- 03提取网站联系信息
- 04收集并比较竞争对手广告
- 05分析多个来源的趋势
适用场景
- 01监测有关特定主题的社交帖子
- 02寻找商业线索并补充联系信息
- 03比较竞争对手的广告活动
- 04发现并比较跨平台趋势
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ casper-studios/ casper-marketplace --skill apify-scrapers安装后在 Claude Code 中输入/apify-scrapers确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/contact-enrichment.mdfacebook.mdgoogle-maps.mdinstagram.mdlinkedin.mdmulti-platform.mdreddit.mdtwitter.mdurl-detect.mdreferences/workflows/audience-analysis.mdcompetitor-ads.mdcompetitor-intel.mdinfluencer-discovery.mdlead-generation.mdtrend-analysis.mdscripts/analyze_audience.pyanalyze_trends.pydiscover_influencers.pyenrich_contacts.pyscrape_competitor_ads.pyscrape_content_by_url.pyscrape_facebook.pyscrape_google_maps.pyscrape_instagram.pyscrape_linkedin_posts.pyscrape_multi_platform.pyscrape_reddit_ai_tech.pyscrape_twitter_ai_trends.py详细介绍
Apify 爬虫
概览
使用 Apify actors 抓取主流社交平台的内容。每个平台都针对成本和质量进行了优化设置。
快速决策树
What do you want to scrape?
│
├── Social Media Posts
│ ├── Twitter/X → references/twitter.md
│ │ └── Script: scripts/scrape_twitter_ai_trends.py
│ │
│ ├── Reddit → references/reddit.md
│ │ └── Script: scripts/scrape_reddit_ai_tech.py
│ │
│ ├── LinkedIn → references/linkedin.md
│ │ └── Script: scripts/scrape_linkedin_posts.py
│ │
│ ├── Instagram → references/instagram.md
│ │ └── Script: scripts/scrape_instagram.py
│ │ └── Modes: profile, posts, hashtag, reels, comments
│ │
│ ├── Facebook → references/facebook.md
│ │ └── Script: scripts/scrape_facebook.py
│ │ └── Modes: page, posts, reviews, groups, marketplace
│ │
│ ├── TikTok → references/multi-platform.md
│ │ └── Script: scripts/scrape_multi_platform.py
│ │
│ └── YouTube → references/multi-platform.md
│ └── Script: scripts/scrape_multi_platform.py
│
├── Business/Places
│ ├── Google Maps businesses → references/google-maps.md
│ │ └── Script: scripts/scrape_google_maps.py
│ │ └── Modes: search, place, reviews
│ │
│ └── Contact info from websites → references/contact-enrichment.md
│ └── Script: scripts/scrape_contact_info.py
│ └── Extract: emails, phone numbers, social profiles
│
├── Auto-detect URL type → references/url-detect.md
│ └── Script: scripts/scrape_content_by_url.py
│
├── Trend Analysis (NEW)
│ └── Enriched trend analysis → workflows/trend-analysis.md
│ └── Script: scripts/analyze_trends.py
│ └── Features: velocity scoring, lifecycle staging, opportunity scoring
│
└── Workflows (multi-step)
├── Lead generation → workflows/lead-generation.md
├── Influencer discovery → workflows/influencer-discovery.md
├── Competitor analysis → workflows/competitor-intel.md
├── Trend analysis → workflows/trend-analysis.md
└── Competitor Ads Intelligence (NEW) → workflows/competitor-ads.md
└── Script: scripts/scrape_competitor_ads.py
└── Platforms: Facebook Ads Library, Google Ads Transparency
└── Features: Spend estimates, creative analysis, benchmarking
环境设置
# Required in .env
APIFY_TOKEN=apify_api_xxxxx
获取 API 密钥:https://console.apify.com/account/integrations
常见用法
抓取 Twitter 热门趋势
python scripts/scrape_twitter_ai_trends.py --query "AI agents" --max-tweets 50
抓取 Reddit 讨论
python scripts/scrape_reddit_ai_tech.py --subreddits "MachineLearning,LocalLLaMA" --max-posts 100
抓取 LinkedIn 作者
python scripts/scrape_linkedin_posts.py author "https://linkedin.com/in/username" --max-posts 30
自动检测并抓取 URL
python scripts/scrape_content_by_url.py "https://x.com/user/status/123456"
抓取 Instagram 个人主页
python scripts/scrape_instagram.py profile "https://instagram.com/username" --max-posts 20
抓取 Instagram 话题标签
python scripts/scrape_instagram.py hashtag "#artificialintelligence" --max-posts 50
抓取 Instagram Reels
python scripts/scrape_instagram.py reels "https://instagram.com/username" --max-reels 30
抓取 Facebook 公共主页
python scripts/scrape_facebook.py page "https://facebook.com/pagename" --max-posts 50
抓取 Facebook 评价
python scripts/scrape_facebook.py reviews "https://facebook.com/pagename" --max-reviews 100
抓取 Facebook Marketplace
python scripts/scrape_facebook.py marketplace "laptops in san francisco" --max-items 30
抓取 Google Maps 商家信息
python scripts/scrape_google_maps.py search "AI consulting firms in New York" --max-results 50
抓取 Google Maps 评价
python scripts/scrape_google_maps.py reviews "ChIJN1t_tDeuEmsRUsoyG83frY4" --max-reviews 100
从网站提取联系信息
python scripts/scrape_contact_info.py "https://example.com" --depth 2
批量补充联系信息
python scripts/scrape_contact_info.py --urls-file companies.txt --output contacts.json
抓取竞争对手广告(单个竞争对手)
python scripts/scrape_competitor_ads.py "Nike" --platforms facebook google --country US --days 30
比较多个竞争对手的广告
python scripts/scrape_competitor_ads.py "Nike" "Adidas" "Puma" --compare --output comparison.json
按关键词发现广告主
python scripts/scrape_competitor_ads.py --search "running shoes" --country US --max-ads 200
按媒体类型筛选竞争对手广告
python scripts/scrape_competitor_ads.py "Netflix" "Disney+" --platforms facebook --media-types video --days 7
分析趋势(新增)
# Analyze specific topic with enrichments
python scripts/analyze_trends.py "artificial intelligence" --sources google instagram tiktok --days 90
# Discover trending topics in category
python scripts/analyze_trends.py --category technology --discover --top 50
# Compare multiple trends
python scripts/analyze_trends.py "AI" "blockchain" "metaverse" --compare
# Export HTML trend report
python scripts/analyze_trends.py "sustainable fashion" --format html --output trend_report.html
成本估算
| 平台 | Actor | 单项成本 |
|---|---|---|
| kaitoeasyapi/twitter-x-data-tweet-scraper | ~$0.00025 | |
| trudax/reddit-scraper | ~$0.001-0.005 | |
| harvestapi/linkedin-post-search | ~$0.01-0.05 | |
| YouTube | streamers/youtube-scraper | ~$0.01-0.05 |
| TikTok | clockworks/tiktok-scraper | ~$0.005 |
| Instagram(个人主页) | apify/instagram-profile-scraper | ~$0.005 |
| Instagram(帖子) | apify/instagram-post-scraper | ~$0.002-0.005 |
| Instagram(话题标签) | apify/instagram-hashtag-scraper | ~$0.002-0.005 |
| Instagram(Reels) | apify/instagram-reel-scraper | ~$0.005-0.01 |
| Instagram(评论) | apify/instagram-comment-scraper | ~$0.001-0.003 |
| Facebook(公共主页) | apify/facebook-pages-scraper | ~$0.005-0.01 |
| Facebook(帖子) | apify/facebook-posts-scraper | ~$0.003-0.005 |
| Facebook(评价) | apify/facebook-reviews-scraper | ~$0.002-0.005 |
| Facebook(群组) | apify/facebook-groups-scraper | ~$0.005-0.01 |
| Facebook(Marketplace) | apify/facebook-marketplace-scraper | ~$0.005-0.01 |
| Google Maps(搜索) | compass/crawler-google-places | ~$0.01-0.02 |
| Google Maps(地点) | compass/google-maps-business-scraper | ~$0.01 |
| Google Maps(评价) | compass/google-maps-reviews-scraper | ~$0.003-0.005 |
| 联系信息补充 | lukaskrivka/contact-info-scraper | ~$0.01-0.03 |
| Google Trends | apify/google-trends-scraper | ~$0.01 |
| 趋势分析(多项) | 多个 actors | ~$0.50-1.50/run |
| Facebook Ads Library | apify/facebook-ads-scraper | ~$0.75/1K ads |
| Facebook Ads(替代方案) | curious_coder/facebook-ads-library-scraper | ~$0.50/1K ads |
| Google Ads Transparency | lexis-solutions/google-ads-scraper | ~$1.00/1K ads |
| Google Ads(替代方案) | xtech/google-ad-transparency-scraper | ~$0.80/1K ads |
输出位置
所有抓取的数据都会保存到 .tmp/,文件名中包含时间戳:
.tmp/twitter_ai_trends_YYYYMMDD.json.tmp/reddit_ai_tech_YYYYMMDD.json.tmp/linkedin_posts_YYYYMMDD_HHMMSS.json
安全说明
凭据处理
- 将
APIFY_TOKEN存储在.env文件中(切勿提交到 git) - 定期通过 Apify Console 轮换 API 令牌
- 切勿在脚本输出中记录或打印 API 令牌
- 使用环境变量,而不是硬编码的值
数据隐私
- 抓取的数据仅包含公开可用的内容
- 社交媒体帖子可能包含 PII(姓名、用户名、个人资料信息)
- 数据在本地存储于
.tmp/目录中 - actor 运行完成后,Apify 不会保留任何数据
- 考虑数据最小化原则——只抓取所需内容
访问范围
- Apify 令牌拥有完整的账户访问权限(没有细粒度的权限范围)
- 如有需要,请为不同项目使用独立的 Apify 账户
- 通过 Apify Console 控制面板监控用量
合规注意事项
- 服务条款:遵守各平台的服务条款(Twitter、Reddit、LinkedIn)
- 速率限制:Actor 内置了速率限制,以避免被封禁
- Robots.txt:某些 Actor 可能会绕过 robots.txt,请负责任地使用
- GDPR:如果涉及欧盟居民,抓取的个人身份信息可能受 GDPR 约束
- 道德使用:仅抓取公开数据;绝不绕过身份验证
- 代理伦理:应合乎道德地使用住宅代理
故障排查
常见问题
问题:Actor 运行失败
**症状:**脚本以“Actor run failed”或超时错误终止 **原因:**Actor ID 无效、代理额度不足或 Actor 配置有问题 解决方案:
- 确认脚本中的 Actor ID 正确无误
- 在 Apify Console 中检查 Actor 运行日志
- 确保代理设置符合 Actor 的要求
- 先尝试使用默认代理设置运行
问题:返回结果为空
**症状:**脚本运行完成,但返回 0 个项目 **原因:**平台屏蔽了内容、查询无效或代理被检测到 解决方案:
- 尝试更换代理类型(住宅代理或数据中心代理)
- 简化搜索查询
- 减少请求的结果数量
- 检查平台是否正在阻止抓取尝试
问题:被平台限制速率
**症状:**脚本报 429 错误或显示“rate limited”消息 **原因:**短时间内请求过多 解决方案:
- 在请求之间添加延迟(Actor 设置)
- 减少并发请求
- 使用代理轮换
- 等待冷却期结束后重试
问题:API 令牌无效
**症状:**身份验证错误或显示“invalid token”消息 **原因:**令牌已过期、被撤销或设置不正确 解决方案:
- 在 Apify Console 中重新生成 API 令牌
- 确认令牌已正确设置在
.env文件中 - 检查令牌是否有前导或尾随空格
- 确保已加载
APIFY_TOKEN环境变量
问题:代理连接错误
**症状:**连接超时或代理错误 **原因:**代理池耗尽或存在地理位置限制问题 解决方案:
- 切换代理类型(基础、住宅或数据中心)
- 在 Apify Console 中确认代理额度余额
- 尝试其他代理国家/地区
- 禁用代理,测试其是否为根本原因
资源
平台参考
- references/twitter.md - Twitter/X 抓取详情
- references/reddit.md - 使用 subreddit 定向抓取 Reddit
- references/linkedin.md - LinkedIn 帖子抓取(作者或搜索模式)
- references/instagram.md - Instagram 个人主页、帖子、话题标签、短视频和评论抓取
- references/facebook.md - Facebook 公共主页、帖子、评论、群组和 Marketplace 抓取
- references/multi-platform.md - TikTok 和 YouTube 抓取
- references/url-detect.md - 自动检测 URL 类型并抓取
商业/地点参考
- references/google-maps.md - Google Maps 商业搜索、地点详情和评论
- references/contact-enrichment.md - 从网站提取电子邮件、电话号码和社交主页
工作流参考
- workflows/lead-generation.md - 多步骤潜在客户开发工作流
- workflows/influencer-discovery.md - 跨平台寻找和分析网红
- workflows/competitor-intel.md - 竞争情报收集工作流
- workflows/trend-analysis.md - 带评分的多平台趋势分析及信息增强
集成模式
抓取并增强信息
技能: apify-scrapers → parallel-research **使用场景:**抓取社交媒体帖子,然后通过深度研究补充信息 流程:
- 抓取 Twitter/Reddit 上提及某个主题的帖子
- 从帖子中提取公司名称或 URL
- 使用 parallel-research 获取每家公司的详细信息
抓取并总结
技能: apify-scrapers → content-generation 使用场景: 根据社交媒体趋势创作新闻简报内容 流程:
- 抓取 Twitter 上热门的 AI 帖子
- 将抓取的数据传递给 content-generation 进行总结
- 生成格式化的新闻简报板块
抓取并归档
技能: apify-scrapers → google-workspace 使用场景: 将抓取的数据保存到 Google Drive,供团队访问 流程:
- 抓取目标账号发布的 LinkedIn 帖子
- 将数据格式化为 CSV 或 JSON
- 通过 google-workspace 将数据上传到 Google Drive 客户端文件夹
趋势分析 + 内容策略
技能: apify-scrapers(trend-analysis)→ content-generation 使用场景: 识别热门话题并制定内容策略 流程:
- 运行趋势分析:
python scripts/analyze_trends.py "AI productivity" --sources all - 查看生命周期阶段和机会得分
- 使用 content-generation 为高机会趋势创作内容
- 聚焦速度得分较高的新兴趋势
竞争趋势监控
技能: apify-scrapers(trend-analysis)→ parallel-research 使用场景: 监控竞争对手在热门话题中的可见度 流程:
- 分析行业趋势:
python scripts/analyze_trends.py --category "your-industry" --discover - 对比你的品牌与竞争对手在这些趋势中的表现
- 使用 parallel-research 深入调查差距
- 生成竞争情报报告