Skip to content

Instantly share code, notes, and snippets.

@auryn31
Last active Sep 25, 2019
Embed
What would you like to do?
const axios = require('axios').default;
const JSDOM = require('jsdom').JSDOM;
module.exports.price = async event => {
var encoded_url = encodeURI("https://www.amazon.de/Raspberry-Pi-ARM-Cortex-A72-Bluetooth-Micro-HDMI/dp/B07TC2BK1X");
const res = await axios.get(encoded_url);
const document = new JSDOM(res.data).window.document;
const title_with_whitespace = document.querySelector("#productTitle").textContent;
const title = title_with_whitespace.replace(/(?:\r\n|\r|\n)/g, '').trim();
const price_with_ending = document.querySelector("#priceblock_ourprice").textContent;
const price = price_with_ending.substring(0, price_with_ending.length - 2).replace(',', '.');
return {
statusCode: res.status,
body: JSON.stringify({
title: title,
price: price
})
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment