diff --git a/README.md b/README.md index 92b0fd7..e5bd8d7 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,21 @@ google('node.js best practices', function (err, res){ ``` +### Search Within Different Categories + +You can also specify the type of the Google search. + +```js +var google = require('google') + +google.searchType = 'videos' + +google('node.js best practices', function (err, res){ + … +}) +``` + + ### Set Request Options You can specify the options to be passed to request, see the [request module](https://github.com/request/request) for all available options. diff --git a/lib/google.js b/lib/google.js index bf5d0f0..c2c6188 100644 --- a/lib/google.js +++ b/lib/google.js @@ -43,6 +43,17 @@ var igoogle = function (query, start, callback) { if (google.timeSpan) { URL = URL.indexOf('tbs=qdr:') >= 0 ? URL.replace(/tbs=qdr:[snhdwmy]\d*/, 'tbs=qdr:' + google.timeSpan) : URL.concat('&tbs=qdr:', google.timeSpan) } + + if (google.searchType=='videos') { + URL+='&tbm=vid' + } + else if (google.searchType=='news'){ + URL+='&tbm=nws' + } + else if (google.searchType=='books'){ + URL+='&tbm=bks' + } + var newUrl = util.format(URL, google.protocol, google.tld, google.lang, querystring.escape(query), start, google.resultsPerPage) var requestOptions = { url: newUrl,