I have a small program that needs to capture icons from sites using node.js. This works in most cases, but with apple.com I get errors that I cannot understand or fix:
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() {
});
});
When I make this request, the response will be as follows:
<head><body> This object may be found <a HREF="http://www.apple.com/favicon.ico">here</a> </body>
As a result, I changed the above code in almost every possible way with the hostname options in the client creation step and the url request using "www.apple.com", but usually I just get errors from node as follows:
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
Also, I am not interested in using google service to capture icons.
source
share