Skip to content

Instantly share code, notes, and snippets.

@jslnriot
Created April 30, 2019 17:34
Show Gist options
  • Save jslnriot/31d7bf0a721655be349079b5744789db to your computer and use it in GitHub Desktop.
Save jslnriot/31d7bf0a721655be349079b5744789db to your computer and use it in GitHub Desktop.
import axios from 'axios';
import cherrio from 'cheerio';
async function getHTML(productURL) {
const { data: html } = await axios.get(productURL, {
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'
}
})
.catch(function (error) {
console.log(error);
})
return html;
}
async function getAmazonPrice(html) {
const $ = cherrio.load(html)
const span = $('#priceblock_ourprice')
return span.html();
}
export { getHTML, getAmazonPrice };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment