Scraping Google Maps Place Data with NodeJS

Scraping-Google-Maps-Place-Data-with-NodeJS.png

This is a step-by-step guide on scraping Google maps place data with NodeJS.

What would be extracted?

What-would-be-extracted.png

Preparation

Preparation.png

Initially, we have to make a project in Node.js* and add npm packages , puppeteer-extra, puppeteer and puppeteer-extra-plugin-stealth for controlling Chromium (or Firefox, or Chrome but now we can only work with Chromium that is utilized by default) with a DevTools Protocol in both headless and non-headless modes.

To do that, in a directory with a project, open a command line to enter npm i puppeteer puppeteer-extra puppeteer-extra-plugin-stealth and npm init -y.

Note: In addition, you can utilize puppeteer with no extensions, but we strongly suggest to use that with puppeteer-extra-plugin-stealth and puppeteer-extra to prevent site detection that you are using a headless Chromium or a web driver. You could check that on a Chrome headless test site. The screenshot given here shows the difference.

Procedure

Procedure.png

Chrome extension SelectorGadget was used for grabbing CSS selectors just by clicking on required elements in a browser. The Gif image below shows the approach of choosing various parts of results.

Complete code

Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS-Complete-code

Code clarification

After that, we "say" puppeteer and use StealthPlugin to write a place URL:

After that, we will write a function to get place information from a page:

And lastly, a function for controlling a browser, and find information:

Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code

Output

img\Scraping-Google-Maps-Place-Data-with-NodeJS\Output.png Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code

Google Maps Places Result API

Instead, you can utilize a Google Maps Places Result API from iWeb Data Scraping.

Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code

The difference here is that you don’t require writing any codes from the scratch and sustain it. You might also experience blocking from Google and varying selectors that will break a parser. As an alternative, you just have to repeat a structured JSON to get the required data. Check out your playground.

Initially, we have to make installation of google-search-results-nodejs. For doing this, you have to pass in the console: npm i google-search-results-nodejs

Note: For making search, we want a data parameter that must get set in next format:

Code explanation

Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code

Announce constants from necessary libraries:

After that, we write the required parameters to make a request:

After that, we wrap a search method from iWeb Data Scraping library with the promise to work further with search results:

And lastly, run a getJson function which gets place data and returns that:

Output

Announce constants from necessary libraries:

Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code Scraping-Google-Maps-Place-Data-with-NodeJS- Complete-code

Still if you are not comfortable with these long codes or if you want more clarity about web scraping Google Maps Places using NodeJS then contact iWeb Data Scraping now!

You can also contact us for all your mobile app scraping and web scraping services requirements.

Let’s Discuss Your Project