scraping-instagram-posts-by-hashtag

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scraping Instagram Posts by Hashtag

按话题标签抓取Instagram帖子

Raw Instagram post dataset for any hashtag. Returns post-level metadata including engagement and author info.
任意话题标签的原始Instagram帖子数据集。返回包含互动数据和作者信息的帖子级元数据。

Prerequisites

前提条件

  • APIFY_TOKEN
    environment variable set
  • Optional: Apify MCP server installed
  • 设置
    APIFY_TOKEN
    环境变量
  • 可选:安装Apify MCP服务器

Inputs

输入参数

ParameterTypeRequiredDefaultNotes
startUrls
arrayOptional
[]
Instagram hashtag search URLs
keyword
stringOptionalHashtag keyword to search (e.g.
fitness
)
getReels
booleanOptional
false
Include Reels in results
getPosts
booleanOptional
true
Include regular posts in results
until
stringOptionalDate filter (YYYY-MM-DD)
maxItems
numberOptionalUnlimitedMaximum posts to return
customMapFunction
stringOptionalJavaScript function to transform each output object
参数类型是否必填默认值说明
startUrls
数组可选
[]
Instagram话题标签搜索链接
keyword
字符串可选要搜索的话题标签关键词(例如
fitness
getReels
布尔值可选
false
是否在结果中包含Reels短视频
getPosts
布尔值可选
true
是否在结果中包含常规帖子
until
字符串可选日期过滤器(格式:YYYY-MM-DD)
maxItems
数字可选无限制返回的最大帖子数量
customMapFunction
字符串可选用于转换每个输出对象的JavaScript函数

Workflow

工作流程

Progress:
- [ ] Step 1: Normalize hashtag input
- [ ] Step 2: Run instagram-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Deliver post dataset
Progress:
- [ ] Step 1: Normalize hashtag input
- [ ] Step 2: Run instagram-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Deliver post dataset

Step 2: Run the Actor

步骤2:运行Actor

Recommended — run_actor.js (handles waiting, output, and file saving automatically):
bash
undefined
推荐方式 — run_actor.js(自动处理等待、输出和文件保存):
bash
undefined

Quick answer (prints table to chat)

快速输出(在聊天窗口打印表格)

node scripts/run_actor.js
--actor "apidojo~instagram-hashtag-scraper"
--input '{"param": "value"}'
node scripts/run_actor.js
--actor "apidojo~instagram-hashtag-scraper"
--input '{"param": "value"}'

Save as CSV

保存为CSV格式

node scripts/run_actor.js
--actor "apidojo~instagram-hashtag-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
node scripts/run_actor.js
--actor "apidojo~instagram-hashtag-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv

Save as JSON

保存为JSON格式

node scripts/run_actor.js
--actor "apidojo~instagram-hashtag-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> `APIFY_TOKEN` must be set in environment or `.env` file.

**If Apify MCP is available:**
Tool: apify:run-actor Actor: "apidojo~instagram-hashtag-scraper" Input: { "keywords": ["tag1", "tag2"], "maxItems": 100, "mediaType": "all" }

**REST API fallback:**
```bash
curl -X POST \
  "https://api.apify.com/v2/acts/apidojo~instagram-hashtag-scraper/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"keywords": ["tag1"], "maxItems": 100}'
Save
id
as
RUN_ID
. Poll until
status = SUCCEEDED
:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID?token=$APIFY_TOKEN" | grep '"status"'
Fetch results:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?token=$APIFY_TOKEN&format=json"
node scripts/run_actor.js
--actor "apidojo~instagram-hashtag-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> `APIFY_TOKEN`必须在环境变量或`.env`文件中设置。

**如果Apify MCP可用:**
Tool: apify:run-actor Actor: "apidojo~instagram-hashtag-scraper" Input: { "keywords": ["tag1", "tag2"], "maxItems": 100, "mediaType": "all" }

**REST API备用方案:**
```bash
curl -X POST \
  "https://api.apify.com/v2/acts/apidojo~instagram-hashtag-scraper/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"keywords": ["tag1"], "maxItems": 100}'
id
保存为
RUN_ID
,轮询直到
status = SUCCEEDED
:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID?token=$APIFY_TOKEN" | grep '"status"'
获取结果:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?token=$APIFY_TOKEN&format=json"

Step 3: Handle Edge Cases

步骤3:处理边缘情况

  • Banned hashtag: Instagram hides some hashtags — returns 0. Try parent category.
  • Only top posts returned: Instagram limits hashtag feeds; very popular tags may return only top posts.
  • Private account posts: Post metadata visible but media URL may be restricted.
  • 被禁用的话题标签:Instagram会隐藏部分话题标签,此时返回结果为0。可尝试使用上级分类标签。
  • 仅返回热门帖子:Instagram对话题标签的信息流有限制,非常热门的标签可能仅返回热门帖子。
  • 私人账号帖子:帖子元数据可见,但媒体链接可能受限制。

Output Format

输出格式

undefined
undefined

Instagram Post Dataset: #<hashtag>

Instagram Post Dataset: #<hashtag>

Posts collected: N | Media type: all/image/video
Post IDAuthorCaption (truncated)LikesCommentsTypeTimestamp
.....................
Available fields: id, ownerUsername, caption, likesCount, commentsCount, type, timestamp, url, mediaUrl, hashtags, mentions
undefined
已收集帖子数:N | 媒体类型:全部/图片/视频
帖子ID作者标题(截断版)点赞数评论数类型时间戳
.....................
可用字段:id, ownerUsername, caption, likesCount, commentsCount, type, timestamp, url, mediaUrl, hashtags, mentions
undefined

Troubleshooting

故障排除

0 results: Hashtag may be banned or restricted by Instagram. Rate limiting: Keep
maxItems
≤ 200 per run; space runs 5 minutes apart.
无结果返回:该话题标签可能被Instagram禁用或限制。 速率限制:每次运行的
maxItems
保持≤200;运行间隔至少5分钟。