Skip to content

Instantly share code, notes, and snippets.

@adrianhorning08
Created September 16, 2025 19:33
Show Gist options
  • Select an option

  • Save adrianhorning08/5b4858965a66ace18899e0404be389c9 to your computer and use it in GitHub Desktop.

Select an option

Save adrianhorning08/5b4858965a66ace18899e0404be389c9 to your computer and use it in GitHub Desktop.
Duck Duck Go parser
import * as cheerio from "cheerio";
function jsonifyDuckDuckGo(html) {
try {
const $ = cheerio.load(html);
const results = [];
$(".results_links")
.get()
.forEach((result) => {
const title = $(result).find("h2").text().trim();
const url = $(result)
.find(".result__url")
.attr("href")
.trim()
?.replace("//duckduckgo.com/l/?uddg=", "")
?.split("&rut=")[0];
const description = $(result).find(".result__snippet").text().trim();
results.push({
title,
url: url ? decodeURIComponent(url) : null,
description,
});
});
return results;
} catch (error) {
console.log("error at jsonifyDuckDuckGo", error.message);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment