title: Node.js HTMLParser iterating more than one time
body: <p>I have this simple HTMLParser in Node.js using the http module:</p>
  
  <pre><code>var http = require('http');
  var options = {
    hostname: 'www.google.com',
    port: 80,
    path: '/',
    method: 'GET'
  };
  
  var req = http.request(options, function(res) {
    res.setEncoding('utf8');
    res.on('data', function (chunk) {  
      var title1 = chunk.indexOf("&lt;title&gt;");  
      var title2 = chunk.indexOf("&lt;/title&gt;"); 
      var titl = chunk.substring(title1 + 7);
      var result = titl.substring(0, titl.indexOf("&lt;/title&gt;"));
      console.log("Title is : " + result);
    });
  req.end();
  });
  
  req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
  });
  
  req.end();
  </code></pre>
  
  <p>and when executed, iterates more than once, so I get this output in the command line and it varies but always iterates more than once.</p>
  
  <pre><code>Title is: Google
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
   Title is:
  </code></pre>
  
  <p>Any help? Thanks in advance!</p>