Scrape Google Maps and query top-rated places with DuckDB
Trigger an Apify Google Maps scraper synchronously and pipe the resulting JSON dataset directly into DuckDB to find top-rated locations using SQL.
Setup
- → curl
- → duckdb
- → Export $APIFY_TOKEN with your Apify API token
Cost per run
$0.01 per run (Apify Pay-as-you-go)
The one-liner
$ curl -s -X POST "https://api.apify.com/v2/acts/apify~google-maps-scraper/run-sync-get-dataset-items?token=$APIFY_TOKEN" -H 'Content-Type: application/json' -d '{"searchStringsArray":["specialty coffee in Brooklyn"],"maxCrawledPlacesPerSearch":20}' | duckdb -c "SELECT title, totalScore, reviewsCount, address FROM read_json_auto('/dev/stdin') WHERE totalScore >= 4.5 ORDER BY reviewsCount DESC LIMIT 3;"What each stage does
- [01] curl
curl -s -X POST "https://api.apify.com/v2/acts/apify~google-maps-scraper/run-syn…Synchronously runs the Apify Google Maps Scraper actor and returns the dataset items as JSON. - [02] apify
-d '{"searchStringsArray":["specialty coffee in Brooklyn"],"maxCrawledPlacesPerS…Passes the scraping configuration, limiting results to 20 to keep the synchronous request fast. - [03] duckdb
| duckdb -c "SELECT title, totalScore, reviewsCount, address ..."Pipes the JSON array directly into DuckDB, executing a SQL query to filter and sort the places. - [04] duckdb
FROM read_json_auto('/dev/stdin')Instructs DuckDB to automatically infer the schema from the piped JSON stream.
Expected output (sample)
┌─────────────────┬────────────┬──────────────┬───────────────────────────────────┐ │ title │ totalScore │ reviewsCount │ address │ ├─────────────────┼────────────┼──────────────┼───────────────────────────────────┤ │ Devoción │ 4.6 │ 2104 │ 69 Grand St, Brooklyn, NY 11249 │ │ Sey Coffee │ 4.7 │ 1432 │ 18 Grattan St, Brooklyn, NY 11206 │ │ Partners Coffee │ 4.5 │ 1120 │ 125 N 6th St, Brooklyn, NY 11249 │ └─────────────────┴────────────┴──────────────┴───────────────────────────────────┘
Caveats & tips
- Synchronous Apify runs (run-sync-get-dataset-items) will time out if the scrape takes longer than 5 minutes. For larger scrapes, use asynchronous webhooks.
- Requires an active Apify account and API token. Google Maps scraping consumes Apify compute units (CUs) and proxy usage, which incurs costs.