Created
May 27, 2014 18:38
-
-
Save alanhoff/08086e64c8ae3c0cd56e to your computer and use it in GitHub Desktop.
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
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