Last active
October 4, 2018 21:17
-
-
Save kyletaylored/12965366f61b83180e12bfc859bda353 to your computer and use it in GitHub Desktop.
Venom extractor
This file contains 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
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); | |
} |
This file contains 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": "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