public
Created

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
var sys = require('sys');
var http = require('http');
var url = require('url');
var path = require('path');
 
function search() {
stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', function(term) {
term = term.substring(0, term.length - 1);
var google = http.createClient(80, 'ajax.googleapis.com');
var search_url = "/ajax/services/search/web?v=1.0&q=" + term;
var request = google.request('GET', search_url, {
'host': 'ajax.googleapis.com',
'Referer': 'http://floatingsun.net',
'User-Agent': 'NodeJS HTTP client',
'Accept': '*/*'});
request.on('response', function(response) {
response.setEncoding('utf8');
var body = ""
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
var searchResults = JSON.parse(body);
var results = searchResults["responseData"]["results"];
for (var i = 0; i < results.length; i++) {
console.log(results[i]["url"]);
}
});
});
request.end();
});
}
 
search();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.