Skip to content

Instantly share code, notes, and snippets.

@AnderRV

AnderRV/index.js Secret

Created August 29, 2021 15:08
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 AnderRV/ca79d4886cd10dfd4b9719bee26e62ac to your computer and use it in GitHub Desktop.
Save AnderRV/ca79d4886cd10dfd4b9719bee26e62ac to your computer and use it in GitHub Desktop.
const extractContent = $ =>
$('.product')
.map((_, product) => {
const $product = $(product);
return {
id: $product.find('a[data-product_id]').attr('data-product_id'),
title: $product.find('h2').text(),
price: $product.find('.price').text(),
};
})
.toArray();
// ...
const content = extractContent($);
console.log(content);
// [{ id: '759', title: 'Bulbasaur', price: '£63.00' }, ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment