Created
September 16, 2025 19:33
-
-
Save adrianhorning08/5b4858965a66ace18899e0404be389c9 to your computer and use it in GitHub Desktop.
Duck Duck Go parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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