Extract and Count Link Domains using Firecrawl
Scrapes a webpage using Firecrawl to extract all outgoing links and aggregates them by domain using jq.
Setup
- → Install firecrawl CLI (e.g., npm install -g @mendable/firecrawl-cli)
- → Set FIRECRAWL_API_KEY environment variable
- → Install jq
Cost per run
Free tier available for Firecrawl, otherwise per-page API cost.
The one-liner
$ firecrawl scrape "https://news.ycombinator.com" --json | jq -r '.data.linksOnPage[]? | select(test("^https?://")) | capture("https?://(?<domain>[^/]+)").domain' | sort | uniq -c | sort -nr | head -n 5What each stage does
- [01] firecrawl
firecrawl scrape "https://news.ycombinator.com" --jsonScrapes the target URL and outputs the extracted page data and metadata as JSON. - [02] jq
jq -r '.data.linksOnPage[]? | select(test("^https?://")) | capture("https?://(?<…Parses the JSON output, filters for valid HTTP/HTTPS URLs, and uses a regex capture to extract just the domain name. - [03] sort
sort | uniq -cAlphabetically sorts the extracted domains to group identical ones, then counts the occurrences of each. - [04] head
sort -nr | head -n 5Sorts the counted domains in descending numerical order and limits the output to the top 5 most frequently linked domains.
Expected output (sample)
45 news.ycombinator.com 12 github.com 5 en.wikipedia.org 3 twitter.com 2 www.nytimes.com
Caveats & tips
- Requires a valid Firecrawl API key set in your environment variables; scraping large sites may consume your API credits quickly.
- The regex in jq assumes standard http/https URLs and will drop relative paths or malformed links.