Created
August 26, 2021 15:31
-
-
Save rob-gordon/9cb58e631a34f8701648f8a50748f51e to your computer and use it in GitHub Desktop.
get idiom
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
#!/usr/bin/env node | |
const request = require("request"); | |
const cheerio = require("cheerio"); | |
const args = process.argv.slice(2); | |
const search = args[0]; | |
if (!search) throw new Error("Must pass search term"); | |
const url = `https://idioms.thefreedictionary.com/${search.replace( | |
/ /gi, | |
"+" | |
)}`; | |
request(url, function (_error, _response, page) { | |
if (!page) throw new Error("Error Loading Page"); | |
const $ = cheerio.load(page); | |
const ul = $("ul.idiKw"); | |
if (ul.length) { | |
$(ul) | |
.find("li a") | |
.each((i, el) => { | |
console.log($(el).text()); | |
}); | |
} else { | |
console.log("No Results List"); | |
} | |
}); |
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
{ | |
"name": "gidiom", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"bin": "./index.js", | |
"dependencies": { | |
"cheerio": "^1.0.0-rc.10", | |
"request": "^2.88.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment