title: Grabbing favicons with node.js
body: <p>I've got a little program that needs to grab favicons from sites using node.js. This works in most cases, but with apple.com, I get errors that I can't understand or fix:</p>
  
  <pre><code>    var sys= require('sys');
      var fs= require('fs');
      var http = require('http');
  
      var rurl = http.createClient(80, 'apple.com');
      var requestUrl = 'http://www.apple.com/favicon.ico';
      var request = rurl.request('GET', requestUrl, {"Content-Type": "image/x-icon", "host" : "apple.com" });
      request.end();
  
      request.addListener('response', function (response)
      {
              response.setEncoding('binary');
              var body = '';
              response.addListener('data', function (chunk) {
                      body += chunk;
              });
              response.addListener("end", function() {
              });
      });
  </code></pre>
  
  <p>When I make this request, the response is:</p>
  
  <pre><code>&lt;head&gt;&lt;body&gt; This object may be found &lt;a HREF="http://www.apple.com/favicon.ico"&gt;here&lt;/a&gt; &lt;/body&gt;
  </code></pre>
  
  <p>As a result, I've modified the above code in just about every way possible with variants of the host name in the client creation step and the url request with 'www.apple.com', but typically I just get errors from node as follows:</p>
  
  <pre><code>node.js:63
      throw e;
      ^
  Error: Parse Error
      at Client.ondata (http:901:22)
      at IOWatcher.callback (net:494:29)
      at node.js:769:9
  </code></pre>
  
  <p>Also, I'm not interested in using the google service to grab the favicons.</p>