Now that you have your environment set up, you are now ready to start scraping Google Maps place results with Node.js. As already mentioned above, in order to scrape Google Maps place results you now need to set up the data parameter. Having everything available by now, you can achieve that as following:
const data_id = "0x87c0ef253b04093f:0xafdfd6dc1d3a2b4e" // the data_id we retrieved earlier
const latitude = '38.99313451901278'
const longitude = '-94.59368586441806'
const data = '!4m5!3m4!1s' + data_id + '!8m2!3d' + latitude + '!4d' + longitude
Now, you need to modify your options object to tell our API that you are looking for place results. Having this new data parameter, our API will know exactly what place you need to scrape information about:
const options = {
"method": "GET",
"hostname": "serpapi.webscrapingapi.com",
"port": null,
"path": `/v1?engine=google_maps&api_key=${API_KEY}&type=place&data=${data}`, // this time the type is place and there is no query needed
"headers": {}
};
The resulting script should look like this :
const https = require("https");
const API_KEY = "<YOUR-API-KEY-HERE>" // You can get by creating an account - https://app.webscrapingapi.com/register
const data_id = "0x87c0ef253b04093f:0xafdfd6dc1d3a2b4e" // the data_id we retrieved earlier
const latitude = '38.99313451901278'
const longitude = '-94.59368586441806'
const data = '!4m5!3m4!1s' + data_id + '!8m2!3d' + latitude + '!4d' + longitude
const options = {
"method": "GET",
"hostname": "serpapi.webscrapingapi.com",
"port": null,
"path": `/v1?engine=google_maps&api_key=${API_KEY}&type=place&data=${data}`, // this time the type is place and there is no query needed
"headers": {}
};
const req = https.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
const response = JSON.parse(body.toString());
console.log(response)
});
});
req.end();
And after running this script, you should get back a response looking like this:
place_results: {
title: 'Waldo Pizza',
data_id: '0x89c259a61c75684f:0x79d31adb123348d2',
place_id: 'ChIJT2h1HKZZwokR0kgzEtsa03k',
data_cid: '8778389626880739538',
website: 'https://www.stumptowntogo.com/',
gps_coordinates: { latitude: 38.99313451901278, longitude: -94.59368586 },
reviews_link: 'https://serpapi.webscrapingapi.com/v1?engine=google_maps_reviews&data_id=0x89c259a61c75684f:0x79d31adb123348d2',
place_id_search: 'https://serpapi.webscrapingapi.com/v1?engine=google_maps&type=place&device=desktop&data=!4m5!3m4!1s0x89c259a61c75684f:0x79d31adb123348d2!8m2!3d38.99313451901278!4d-94.59368586',
thumbnail: 'https://lh5.googleusercontent.com/p/AF1QipNtnPBJ2Oi_C2YNamHTXyqU9I8mRBarCIvM5g5v=w408-h272-k-no',
rating: 4.6,
reviews: 2594,
price: '$$',
type: [ 'Pizza restaurant' ],
service_options: { dine_in: true, curbsidepickup: true, no_contactdelivery: true },
extensions: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
open_state: 'Closed',
hours: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object]
],
contact_details: {
address: [Object],
action_1: [Object],
menu: [Object],
phone: [Object],
plus_code: [Object]
},
address: '7433 Broadway St, Kansas City, MO 64114',
images: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
people_also_search_for: [ [Object], [Object], [Object] ],
user_reviews: { summaries: [Array], most_relevant: [Array] },
popular_times: { graph_results: [Object] }
}
}
And that’s it. That means you have managed successfully to scrape the Google Maps place results using our API and you are ready now to use the data obtained for a lot of different purposes such as data analysis, business analysis, machine learning, and more. For further reference and code samples in other 6 programming languages for you to get started, feel free to explore our Google Maps docs.