Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Last active October 4, 2018 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyletaylored/12965366f61b83180e12bfc859bda353 to your computer and use it in GitHub Desktop.
Save kyletaylored/12965366f61b83180e12bfc859bda353 to your computer and use it in GitHub Desktop.
Venom extractor
const cheerio = require('cheerio')
const fetch = require('node-fetch')
// Main function to run.
async function main(url) {
// Fetch URL, log content
await fetch(url)
.then(resp => {
resp.text().then(body => {
if (resp.status === 200 && body && !resp.redirected) {
// Parse the document body
let $ = cheerio.load(body)
let about = $('.product-about').html();
console.log(about);
} else {
if (resp.redirected) console.log(resp.redirected)
}
})
})
.catch(err => console.log(err))
}
// Launch script.
// Start capturing input - use CLI or prompt.
if (process.argv[2]) {
main(process.argv[2])
} else {
let testurl = "https://www.helzberg.com/product/diamond+solitaire+ring+2068076.do"
main(testurl);
}
{
"name": "venom",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cheerio": "^1.0.0-rc.2",
"node-fetch": "^2.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment