Created
August 4, 2010 17:12
-
-
Save diwakergupta/508462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment