DEV Community

Monkey.D.Scraping
Monkey.D.Scraping

Posted on Fully Autonomous

How to Search Threads Posts by Keyword and Export a CSV with curl

A CSV of public Threads posts is easier to audit when you can answer three questions about every row. Which query produced it? When did the search run? Can a reviewer open the source conversation?

Here is a small first run with the Threads Search Scraper we built at Monkey D. Scraping. It asks for up to 50 recent posts about electric bikes from the past seven days. You need an Apify account and API token. The Actor accesses public posts without a Threads login.

Run the keyword search

Set APIFY_TOKEN in your shell environment using your usual secret manager. The request starts a billable Actor run and writes its dataset as CSV. Start with a small limit while checking relevance.

curl --fail --silent --show-error \
  'https://api.apify.com/v2/acts/monkey.d.scraping~threads-search-scraper/run-sync-get-dataset-items?format=csv' \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"keywords":["electric bike"],"maxPosts":50,"sortBy":"recent","startDate":"7 days"}' \
  --output threads-electric-bike.csv
Enter fullscreen mode Exit fullscreen mode

A rolling seven-day window moves each time the command runs. Save the input and execution timestamp with your CSV. For a fixed event, use the date and hour controls in the Actor input to define the same interval for every analyst. If the synchronous request times out, check the run in Apify Console before starting another paid run.

Inspect rows before aggregating

Open the file with a CSV parser. Post text can contain commas and line breaks, so counting lines in a terminal can overstate the result count. This Python snippet prints the field names and the number of records returned, including when a search yields zero rows.

import csv

with open("threads-electric-bike.csv", encoding="utf-8-sig", newline="") as stream:
    reader = csv.DictReader(stream)
    print("Fields:", reader.fieldnames or [])
    print("Post rows:", sum(1 for row in reader))
Enter fullscreen mode Exit fullscreen mode

Open a few source links before counting topics. Look at posts near each end of the interval, then inspect replies alongside their parent text. For instance, a reply saying “too heavy” could describe the frame, the battery or a delivery box. Keep unresolved references as unknown. If you request view counts, preserve missing values separately from observed zeros.

Illustrative example: the same Threads reply expresses launch interest or checkout friction depending on its parent post.

Move from a snapshot to monitoring

Save the validated input as an Apify task and schedule it. The Actor documents an onlyNewPosts setting for recurring delivery. Keep the first dataset as a baseline and record which scheduled run produced each later export. If your downstream import can retry, use a stable post identifier as its key so replaying the same CSV does not double-count mentions.

Open the Actor README and input reference on Apify. This tutorial was written with AI assistance using the public Actor documentation.

Top comments (0)