A module to search and scrape google. This is not sponsored, supported, or affiliated with Google Inc.
This module allows you to search google by scraping the results. It does NOT use the Google Search API. PLEASE DO NOT ABUSE THIS. The intent of using this is convenience vs the cruft that exists in the Google Search API.
This is not sponsored, supported, or affiliated with Google Inc.
Please do not post an issue, email me, tweet me, or in anyway contact me about getting around Google blocking your automated search requests. These sorts of requests are outside the scope of this module. Google has every right to block consumers of their service for any reason. See: #27, #20.
npm install --save google
This prints out the first 50 search results of the query
node.js best practices.
var google =googleresultsPerPage = 25var nextCounter = 0
You can specify results in a specific timeframe. Working values listed below:
var google =// assign one of the values below. Nothing is set by default.googletimeSpan = 'h' // information indexed in the past hourgoogletimeSpan = 'd' // information indexed in the past daygoogletimeSpan = 'w' // information indexed in the past weekgoogletimeSpan = 'm' // information indexed in the past monthgoogletimeSpan = 'y' // information indexed in the past year
You can also specify the TLD of the Google search page and the language. If you change the language you must translate the next page results text to detect the corresponding link.
var google =googlelang = 'de'googletld = 'de'googlenextText = 'Weiter'
You can specify the options to be passed to request, see the request module for all available options.
var google =googlerequestOptions =proxy: ''timeout: 30000localAddress: '127.0.0.1'jar: trueheaders:'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8''Accept-Encoding': 'gzip, deflate''Accept-Language': 'en;q=0.5''Cache-Control': 'max-age=0''Connection': 'keep-alive''DNT': 1
A 'http' or 'https' protocol can be specified after the google object has been created for queries. For example specifying 'http' will search google using the a http://www.google.com query where 'https' will use a https://www.google.com query. If no protocol is specified or any other protocol other then 'http' or 'https' is explicitly passed then this will be set to 'https' by default.
var google =googleprotocol = 'http' // searches google usinggoogleprotocol = 'https' // searches google using
The provided callback will receive a response object as second argument, it has these properties:
url: The URL requested from Google for this search and page
query: The search provided on this call
start: The index of the first link across the links of all pages
links: An array with all the link objects
body: The HTML of the loaded page
$: A cheerio instance of the loaded page
The only backwards-incompatible change from 1.x is that the callback received 3 arguments:
And it now receives a single
res object. The above code should be rewritten to:
Licensed under MIT. See
LICENSE for more details.
Copyright (c) 2012-2015 JP Richardson