Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Librerias basicas
- var express = require('express');
- // Librerias tuyas
- var cheerio = require('cheerio');
- var request = require('request');
- // Crear un server
- var app = express();
- // Home
- app.get('/', function(req, res) {
- var ql = 0;
- var data = [];
- for (var i = 1; i < 150; i++) {
- ql++;
- request('http://www.bricogeek.com/shop/5-aloha?n=5000', function(error, response, html) {
- if (!error && response.statusCode == 200) {
- var $ = cheerio.load(html);
- $('li.ajax_block_product').each(function(i, element) {
- var title = $(this).find('h3 a').text();
- var stock = $(this).find('h3').next().attr('alt');
- var price = $(this).find('span.price').text();
- data.push({title: title, stock: stock, price: price});
- });
- }
- ql--;
- if (ql == 0) {
- res.json(data);
- res.end();
- }
- });
- }
- });
- // Iniciar el server creado
- app.listen(process.env.PORT);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement