Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created May 27, 2014 18:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhoff/08086e64c8ae3c0cd56e to your computer and use it in GitHub Desktop.
Save alanhoff/08086e64c8ae3c0cd56e to your computer and use it in GitHub Desktop.
var cheerio = require('cheerio');
var request = require('request');
var url = 'http://www.americanas.com.br/produto/7112345/geladeira-refrigerador-frost-free-brastemp-clean-brm39-352-litros-inox';
request.get(url, function(err, res, body){
if(err)
throw err;
if(res.statusCode !== 200)
throw new Error('Resporta não OK ' + res.statusCode);
var result = {};
var $ = cheerio.load(body);
// Imagens
result.images = [];
$('.ip-photo').each(function(i, el){
result.images.push($(el).attr('src'));
});
// Nome
result.name = $('h1[itemprop="name"]').text().trim();
// Preço
result.price = $('div .mp-pb-to').text().trim();
// Descrição
result.description = $('div[itemprop="description"]').html();
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment