title: Node.js web scraping with loop on array of URLs
body: <p>I'm trying to build a little script to scrap some data. I'm some basics knowledge in javascript however I'm kind of lost with all the async callback or promises stuff. Here is what I have now :</p>
  
  <pre><code>url = "http://Blablablabla.com";
  
  var shares = function(req, res) {
      request(url, function (error, response, body) {
    if (!error) {
      var $ = cheerio.load(body),
        share = $(".theitemIwant").html();
  
      return res.send(url + ":" + share);
    } else {
      console.log("We've encountered an error: " + error);
    }
  })
  
  }
  </code></pre>
  
  <p>So everything is fine with this piece of code. What I would like to do is :</p>
  
  <ol>
  <li>Using an array of url <code>var urls = [url1,url2,url3,etc...]</code> </li>
  <li>Storing my scrapped data into another array, something like this <code>data = [{url: url1, shares: share},{url: url2, shares: share},etc...]</code></li>
  </ol>
  
  <p>I know I need to use something like this <code>data.push({ urls: url, shares: share})})</code></p>
  
  <p>and I understand that I need to loop over my first url array to push data into my second data array. </p>
  
  <p>however I'm kind of lost with the <code>request</code> method and the way I should deal with async issue in my situation. </p>
  
  <p>thanks !</p>
  
  <p>edit#1 :</p>
  
  <p>I tried this to use promises :</p>
  
  <pre><code>var url = "www.blablabla.com"
  var geturl = request(url, function (error, response, body) {
    if (!error) { return $ = cheerio.load(body) } else 
    { console.log("We've encountered an error: " + error); }
  });
  
  var shares = geturl.then( function() {
      return $(".nb-shares").html();
  })
  </code></pre>
  
  <p>but got the following error <code>geturl.then is not a function</code></p>