Google Search Results in Node.JS
This Node.JS module allows you to scrape and parse Google Search Results using SerpWow. In addition to Search you can also use this module to access the SerpWow Locations API, Batches API and Account API.
All methods support promises and node-style callbacks.
Installation
You can install google-search-results-serpwow with:
$ npm install google-search-results-serpwow
and update with:
$ npm update google-search-results-serpwow
View package on npmjs.com
Documentation
We have included examples here but full SerpWow API documentation is available at the API Docs:
You can also use the API Playground to visually build Google search requests using SerpWow.
Examples
- Simple Example
- Example Response
- Getting an API Key
- Searching with a Location
- Searching Google Places, Google Videos, Google Images, Google Shopping and Google News
- Returning results as JSON, HTML and CSV
- Requesting mobile and tablet results
- Parsing Results
- Paginating results, returning up to 100 results per page
- Search example with all parameters
- Locations API Example
- Account API Example
- Batches API
Requirement
- ES6 basic understanding
- Node.JS coding experience
- Node 7+ and npm installed
Simple Example
Simplest example for a standard query "pizza", returning the Google SERP (Search Engine Results Page) data as JSON.
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // #1. example using promises & async/await { let result = await serpwow; // pretty-print the result console; }; // #2. example using callbacksserpwow ;
Example Response
A snapshot (shortened for brevity) of the JSON response returned is shown below. For details of all of the fields from the Google search results page that are parsed please see the docs.
Getting an API Key
To get a free API Key head over to app.serpwow.com/signup.
Searching with a location
Example of a Google query geo-locating the query as if the user were located in New York.
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // retrieve the search results as JSONserpwow ;
Searching Google Places, Google Videos, Google Images, Google Shopping and Google News
Use the search_type
param to search Google Places, Videos, Images and News. See the Search API Parameters Docs for full details of the additional params available for each search type.
// perform a search on Google News, just looking at blogs, filtering out duplicates, ordered by date, in the last tearserpwow ; // perform a search on Google Places for 'plumber' in Londonserpwow ; // perform an image search on Google Images for "red flowers"serpwow ;
Returning results as JSON, HTML and CSV
SerpWow can return data in JSON, HTML and CSV formats using the json
, html
and csv
methods. For CSV results use the csv_fields
param (docs) to request specific result fields.
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' /* Set up parameters the query (q) and location parameters note that the "location" parameter should be a value returned from the Locations API. We'll re-use the same params for all 3 examples.*/var params = q: 'pizza' location: 'New York,New York,United States' // retrieve the Google search results as JSONserpwow ; // retrieve the Google search results as HTMLserpwow ; // retrieve the Google search results as CSVserpwow ;
Requesting mobile and tablet results
To request that SerpWow renders the Google search results via a mobile or tablet browser use the device
param:
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // set up the mobile paramsvar paramsMobile = q : 'pizza' device : 'mobile' // set up the tablet paramsvar paramsTablet = q : 'pizza' device: 'tablet' // set up the desktop params (note we omit the 'device' param)var paramsDesktop = q: 'pizza' // retrieve the mobile search resultsserpwow ; // retrieve the tablet search resultsserpwow ; // retrieve the desktop search resultsserpwow ;
Parsing results
When making a request via the json
method an object is returned. You can inspect this dict to iterate, parse and store the results in your app.
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // make a simple query, returning JSONserpwow ;
Paginating results, returning up to 100 results per page
Use the page
and num
parameters to paginate through Google search results. The maximum number of results returned per page (controlled by the num
param) is 100 (a Google-imposed limitation) for all search_type
's apart from Google Places, where the maximum is 20. Here's an example.
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // set number of results let numberOfResults = 100; // request the first 100 resultsserpwow ;
Search example with all parameters
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // set up a multiple search parameters, retrieving results as CSV (note the csv_fields param)serpwow ;
Locations API Example
The Locations API allows you to search for SerpWow supported Google search locations. You can supply the full_name
returned by the Locations API as the location
parameter in a Search API query (see Searching with a location example above) to retrieve search results geo-located to that location.
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // retrieve locations matching the query parameters as JSONserpwow ;
Account API Example
The Account API allows you to check your current SerpWow usage and billing information.
var SerpWow = // create the serpwow object, passing in our API keylet serpwow = 'API_KEY' // get our account infoserpwow ;
Batches API
The Batches API allows you to create, update and delete Batches on your SerpWow account (Batches allow you to save up to 15,000 Searches and have SerpWow run them on a schedule).
For more information and extensive code samples please see the Batches API Docs.