Web scraping Google Play App Info with Nodejs
Tags: webscraping, node, serpapi, google
Published: 2022-11-02 17:08:31

<h2 id='what'>What will be scraped</h2>

![what](https://user-images.githubusercontent.com/64033139/197340350-898471cf-3640-4947-9954-a71586429269.png)

📌Note: You can use official the [Google Play Developer API](https://developers.google.com/android-publisher) which has a default limit of [200,000 requests per day](https://developers.google.com/android-publisher/quotas#:~:text=The%20Google%20Play%20Developer%20API,of%20the%20Google%20Cloud%20Console.) for [retrieving the list of reviews and individual reviews](https://developers.google.com/android-publisher/reply-to-reviews#retrieving_reviews).

Also, you can use a complete third-party Google Play Store App scraping solution [google-play-scraper](https://github.com/facundoolano/google-play-scraper). Third-party solutions are usually used to break the quota limit.

This blog post is meant to give an idea and step-by-step examples of how to scrape Google Play Store App using [Cheerio](https://www.npmjs.com/package/cheerio) to create something on your own.

<h2 id='full_code'>Full code</h2>

If you don't need an explanation, have a look at [the full code example in the online IDE](https://replit.com/@MikhailZub/Google-Play-App-Info-with-NodeJS-SerpApi#withCheerio.js)

```javascript
const cheerio = require("cheerio");
const axios = require("axios");

const AXIOS_OPTIONS = {
  headers: {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36",
  }, // adding the User-Agent header as one way to prevent the request from being blocked
  params: {
    id: "com.discord", // Parameter defines the ID of a product you want to get the results for
    hl: "en", // Parameter defines the language to use for the Google search
    gl: "us", // parameter defines the country to use for the Google search
  },
};

function getAppInfo() {
  return axios.get(`https://play.google.com/store/apps/details`, AXIOS_OPTIONS).then(function ({ data }) {
    let $ = cheerio.load(data);

    return {
      productInfo: {
        title: $(".Fd93Bb")?.text().trim(),
        authors: Array.from($(".Vbfug")).map((el) => ({
          name: $(el).find("a > span")?.text().trim(),
          link: `https://play.google.com${$(el).find("a")?.attr("href")}`,
        })),
        extensions: Array.from($(".UIuSk")).map((el) => $(el)?.text().trim().replaceAll(" · ", "")),
        rating: parseFloat($(".TT9eCd")?.text().trim()) || "No rating",
        reviews: $(".wVqUob:first-child .g1rdde")?.text().trim(),
        contentRating: {
          text: $(".wVqUob:last-child .g1rdde > span")?.text().trim(),
          thumbnail: $(".wVqUob:last-child .ClM7O > img")?.attr("srcset")?.slice(0, -3),
        },
        downloads: $(".wVqUob:nth-child(2) .ClM7O")?.text().trim(),
        thumbnail: $(".l8YSdd > img")?.attr("srcset")?.slice(0, -3),
        offers: {
          text: $(".VAgTTd button")?.attr("aria-label"),
          link: $(".VAgTTd button meta[itemprop='url']")?.attr("content"),
          price: $(".VAgTTd button meta[itemprop='price']")?.attr("content"),
        },
      },
      media: {
        video: {
          thumbnail: $(".oiEt0d")?.attr("src"),
          link: $(".IZOk1 button")?.attr("data-trailer-url"),
        },
        images: Array.from($(".ULeU3b img")).map((el) => $(el)?.attr("srcset")?.slice(0, -3)),
      },
      aboutThisApp: {
        snippet: $(".bARER")?.text().trim(),
      },
      badges: Array.from($(".Uc6QCc > div > button")).map((el) => ({
        name: $(el).find("span")?.text().trim(),
      })),
      categories: Array.from($(".Uc6QCc > div > div")).map((el) => {
        const link = `https://play.google.com${$(el).find(" a")?.attr("href")}`;
        const categoryId = link.slice(link.indexOf("category/") + 9);
        return {
          name: $(el).find("span")?.text().trim(),
          link,
          categoryId,
        };
      }),
      updatedOn: $(".TKjAsc .xg1aie")?.text().trim(),
      dataSafety: Array.from($(".wGcURe")).map((el) => {
        const subtext = $(el).find(".jECfAf")?.text().trim() || "No subtext";
        return {
          text: $(el)?.text().trim().replace(subtext, ""),
          subtext,
          link: $(el).find(".jECfAf a")?.attr("href") || "No link",
        };
      }),
      whatsNew: {
        snippet: $("c-wiz[jsrenderer='q8s33d'] .SfzRHd")?.text().trim(),
      },
      reviews: Array.from($(".EGFGHd")).map((el) => ({
        title: $(el).find(".X5PpBb")?.text().trim(),
        avatar: $(el).find(".gSGphe > img")?.attr("srcset")?.slice(0, -3),
        rating: parseInt($(el).find(".Jx4nYe > div")?.attr("aria-label")?.slice(6)),
        snippet: $(el).find(".h3YV2d")?.text().trim(),
        likes: parseInt($(el).find(".AJTPZc")?.text().trim()),
        date: $(el).find(".bp9Aid")?.text().trim(),
        response: $(el).find(".ocpBU .I6j64d")?.text().trim()
          ? {
              title: $(el).find(".ocpBU .I6j64d")?.text().trim(),
              snippet: $(el).find(".ocpBU .ras4vb")?.text().trim(),
              date: $(el).find(".ocpBU .I9Jtec")?.text().trim(),
            }
          : "No response",
      })),
      developerContact: {
        website: $("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ:nth-child(1) .Si6A0c")?.attr("href"),
        email: $("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ:nth-child(2) .Si6A0c")?.attr("href").replace("mailto:", ""),
        address: $(Array.from($("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ .xFVDSb")).find((el) => $(el)?.text().trim() === "Address"))
          .parent()
          .find(".pSEeg")
          ?.text()
          .trim(),
        privacyPolicy: $("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ:last-child .Si6A0c")?.attr("href"),
      },
      similarApps: Array.from($("c-wiz[jsrenderer='G2gJT'] .HcyOxe")).map((block) => ({
        categoryTitle: $(block).find(".cswwxf h2")?.text().trim(),
        seeMoreLink: `https://play.google.com${$(block).find(".cswwxf a")?.attr("href")}`,
        items: Array.from($(block).find(".fUtUMc")).map((app) => {
          const link = `https://play.google.com${$(app).find(".Si6A0c")?.attr("href")}`;
          const appId = link.slice(link.indexOf("?id=") + 4);
          return {
            title: $(app).find(".DdYX5")?.text().trim(),
            link,
            developer: $(app).find(".wMUdtb")?.text().trim(),
            rating: parseFloat($(app).find(".w2kbF")?.text().trim()) || "No rating",
            thumbnail: $(app).find(".T75of")?.attr("srcset")?.slice(0, -3),
            appId,
          };
        }),
      })),
    };
  });
}

getAppInfo().then((result) => console.dir(result, { depth: null }));
```

<h2 id='preparation'>Preparation</h2>

First, we need to create a Node.js\* project and add [`npm`](https://www.npmjs.com/) packages [`cheerio`](https://www.npmjs.com/package/cheerio) to parse parts of the HTML markup, and [`axios`](https://www.npmjs.com/package/axios) to make a request to a website.

To do this, in the directory with our project, open the command line and enter:

```bash
$ npm init -y
```

And then:

```bash
$ npm i cheerio axios
```

\*<span style="font-size: 15px;">If you don't have Node.js installed, you can [download it from nodejs.org](https://nodejs.org/en/) and follow the installation [documentation](https://nodejs.dev/learn/introduction-to-nodejs).</span>

<h2 id='process'>Process</h2>

First of all, we need to extract data from HTML elements. The process of getting the right CSS selectors is fairly easy via [SelectorGadget Chrome extension](https://selectorgadget.com/) which able us to grab CSS selectors by clicking on the desired element in the browser. However, it is not always working perfectly, especially when the website is heavily used by JavaScript.

We have a dedicated [web Scraping with CSS Selectors](https://serpapi.com/blog/web-scraping-with-css-selectors-using-python/#css_gadget) blog post at SerpApi if you want to know a little bit more about them.

The Gif below illustrates the approach of selecting different parts of the results.

![how](https://user-images.githubusercontent.com/64033139/197340486-3ea0c00b-ab9c-4367-ac44-268153a6e3e9.gif)

<h3 id='code_explanation'>Code explanation</h3>

Declare constants from [`cheerio`](https://www.npmjs.com/package/cheerio) and [`axios`](https://www.npmjs.com/package/axios) libraries:

```javascript
const cheerio = require("cheerio");
const axios = require("axios");
```

Next, we write a request options: [`HTTP headers`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers) with [`User-Agent`](https://developer.mozilla.org/en-US/docs/Glossary/User_agent) (is used to act as a "real" user visit. [Default `axios` request user-agent is `axios/<axios_version>`](https://github.com/axios/axios/blob/892c241773e7dda78a969ac1faa9b365e24f6cc8/lib/adapters/http.js#L224) so websites understand that it's a script that sends a request and might block it. [Check what's your user-agent](https://www.whatismybrowser.com/detect/what-is-my-user-agent/)), and the necessary parameters for making a request:

```javascript
const AXIOS_OPTIONS = {
  headers: {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36",
  }, // adding the User-Agent header as one way to prevent the request from being blocked
  params: {
    id: "com.discord", // Parameter defines the ID of a product you want to get the results for
    hl: "en", // Parameter defines the language to use for the Google search
    gl: "us", // parameter defines the country to use for the Google search
  },
};
```

Next, we write a function that makes the request and returns the received data. We received the response from [`axios`](https://www.npmjs.com/package/axios) request that has `data` key that we [destructured](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) and parse it with [`cheerio`](https://www.npmjs.com/package/cheerio):

```javascript
function getAppInfo() {
  return axios.get(`https://play.google.com/store/apps/details`, AXIOS_OPTIONS).then(function ({ data }) {
    let $ = cheerio.load(data);
    ...
  })
}
```

Next, we need to get the different parts of the page using next methods:

- [`$()`](https://api.jquery.com/class-selector/);
- [`text()`](https://api.jquery.com/text/);
- [`trim()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim);
- [`Array.from()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from);
- [`find()`](https://api.jquery.com/find/);
- [`attr()`](https://api.jquery.com/attr/);
- [`slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice);
- [`indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf);
- [`replace()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace).

First, we get main product information:

```javascript
productInfo: {
  title: $(".Fd93Bb")?.text().trim(),
  authors: Array.from($(".Vbfug")).map((el) => ({
    name: $(el).find("a > span")?.text().trim(),
    link: `https://play.google.com${$(el).find("a")?.attr("href")}`,
  })),
  extensions: Array.from($(".UIuSk")).map((el) => $(el)?.text().trim().replaceAll(" · ", "")),
  rating: parseFloat($(".TT9eCd")?.text().trim()) || "No rating",
  reviews: $(".wVqUob:first-child .g1rdde")?.text().trim(),
  contentRating: {
    text: $(".wVqUob:last-child .g1rdde > span")?.text().trim(),
    thumbnail: $(".wVqUob:last-child .ClM7O > img")?.attr("srcset")?.slice(0, -3),
  },
  downloads: $(".wVqUob:nth-child(2) .ClM7O")?.text().trim(),
  thumbnail: $(".l8YSdd > img")?.attr("srcset")?.slice(0, -3),
  offers: {
    text: $(".VAgTTd button")?.attr("aria-label"),
    link: $(".VAgTTd button meta[itemprop='url']")?.attr("content"),
    price: $(".VAgTTd button meta[itemprop='price']")?.attr("content"),
  },
},
```

Next, we get video, images and description info:

```javascript
media: {
  video: {
    thumbnail: $(".oiEt0d")?.attr("src"),
    link: $(".IZOk1 button")?.attr("data-trailer-url"),
  },
  images: Array.from($(".ULeU3b img")).map((el) => $(el)?.attr("srcset")?.slice(0, -3)),
},
aboutThisApp: {
  snippet: $(".bARER")?.text().trim(),
},
```

Next, bages and categories info:

```javascript
badges: Array.from($(".Uc6QCc > div > button")).map((el) => ({
  name: $(el).find("span")?.text().trim(),
})),
categories: Array.from($(".Uc6QCc > div > div")).map((el) => {
  const link = `https://play.google.com${$(el).find(" a")?.attr("href")}`;
  const categoryId = link.slice(link.indexOf("category/") + 9);
  return {
    name: $(el).find("span")?.text().trim(),
    link,
    categoryId,
  };
}),
```

Next, we get when the app was updated, what's new, and data safety info:

```javascript
updatedOn: $(".TKjAsc .xg1aie")?.text().trim(),
dataSafety: Array.from($(".wGcURe")).map((el) => {
  const subtext = $(el).find(".jECfAf")?.text().trim() || "No subtext";
  return {
    text: $(el)?.text().trim().replace(subtext, ""),
    subtext,
    link: $(el).find(".jECfAf a")?.attr("href") || "No link",
  };
}),
whatsNew: {
  snippet: $("c-wiz[jsrenderer='q8s33d'] .SfzRHd")?.text().trim(),
},
```

Next, user reviews:

```javascript
reviews: Array.from($(".EGFGHd")).map((el) => ({
  title: $(el).find(".X5PpBb")?.text().trim(),
  avatar: $(el).find(".gSGphe > img")?.attr("srcset")?.slice(0, -3),
  rating: parseInt($(el).find(".Jx4nYe > div")?.attr("aria-label")?.slice(6)),
  snippet: $(el).find(".h3YV2d")?.text().trim(),
  likes: parseInt($(el).find(".AJTPZc")?.text().trim()),
  date: $(el).find(".bp9Aid")?.text().trim(),
  response: $(el).find(".ocpBU .I6j64d")?.text().trim()
    ? {
        title: $(el).find(".ocpBU .I6j64d")?.text().trim(),
        snippet: $(el).find(".ocpBU .ras4vb")?.text().trim(),
        date: $(el).find(".ocpBU .I9Jtec")?.text().trim(),
      }
    : "No response",
})),
```

Next, developer contact:

```javascript
developerContact: {
  website: $("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ:nth-child(1) .Si6A0c")?.attr("href"),
  email: $("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ:nth-child(2) .Si6A0c")?.attr("href").replace("mailto:", ""),
  address: $(Array.from($("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ .xFVDSb")).find((el) => $(el)?.text().trim() === "Address"))
    .parent()
    .find(".pSEeg")
    ?.text()
    .trim(),
  privacyPolicy: $("c-wiz[jsrenderer='Grlxwe'] .SfzRHd .KC1dQ:last-child .Si6A0c")?.attr("href"),
},
```

And finally, similar apps:

```javascript
similarApps: Array.from($("c-wiz[jsrenderer='G2gJT'] .HcyOxe")).map((block) => ({
  categoryTitle: $(block).find(".cswwxf h2")?.text().trim(),
  seeMoreLink: `https://play.google.com${$(block).find(".cswwxf a")?.attr("href")}`,
  items: Array.from($(block).find(".fUtUMc")).map((app) => {
    const link = `https://play.google.com${$(app).find(".Si6A0c")?.attr("href")}`;
    const appId = link.slice(link.indexOf("?id=") + 4);
    return {
      title: $(app).find(".DdYX5")?.text().trim(),
      link,
      developer: $(app).find(".wMUdtb")?.text().trim(),
      rating: parseFloat($(app).find(".w2kbF")?.text().trim()) || "No rating",
      thumbnail: $(app).find(".T75of")?.attr("srcset")?.slice(0, -3),
      appId,
    };
  }),
})),
```

Now we can launch our parser:

```bash
$ node YOUR_FILE_NAME # YOUR_FILE_NAME is the name of your .js file
```

<h2 id='output'>Output</h2>

```json
{
   "productInfo":{
      "title":"Discord: Talk, Chat & Hang Out",
      "authors":[
         {
            "name":"Discord Inc.",
            "link":"https://play.google.com/store/apps/developer?id=Discord+Inc."
         }
      ],
      "extensions":[
         "In-app purchases"
      ],
      "rating":4.1,
      "reviews":"4.76M reviews",
      "contentRating":{
         "text":"Teen",
         "thumbnail":"https://play-lh.googleusercontent.com/mw_NfsvKM8m6RPv8Fz2GQawCOsqWv010saMnc7zbWalMxuaA9IY8h7E0VMieLxSxAFB98NFeYqbFrXXq=w96-h32-rw"
      },
      "downloads":"100M+",
      "thumbnail":"https://play-lh.googleusercontent.com/0oO5sAneb9lJP6l8c6DH4aj6f85qNpplQVHmPmbbBxAukDnlO7DarDW0b-kEIHa8SQ=s96-rw",
      "offers":{
         "text":"Install",
         "link":"https://play.google.com/store/apps/details?id=com.discord&rdid=com.discord&feature=md&offerId",
         "price":"0"
      }
   },
   "media":{
      "video":{
         "thumbnail":"https://i.ytimg.com/vi/XoCvEM0Ah6E/hqdefault.jpg",
         "link":"https://play.google.com/video/lava/web/player/yt:movie:XoCvEM0Ah6E?autoplay=1&embed=play"
      },
      "images":[
         "https://play-lh.googleusercontent.com/85W8SSlu7z62P5uqatGOxdhX8JJJ7c_p11I_982xaPxMptsE9z4QeZr78Ua_E7A8OQ=w1052-h592-rw",
         ...and other images
      ]
   },
   "aboutThisApp":{
      "snippet":"Discord is where you can make a home for your communities and friends. Where you can stay close and have fun over text, voice, and video chat. Whether you’re part of a school club, a gaming group, a worldwide art community, or just a handful of friends who want to spend time together, Discord makes it easy to talk every day, and hang out more often.CREATE AN INVITE-ONLY PLACE•  Discord servers are organized into topic-based channels where you can collaborate, share, have meetings, or just talk to friends about your day without clogging up a group chat.•  Send a message directly to a friend or call them up with our voice chat feature•  Voice channels make hanging out easy. Got a free moment? Grab a seat in a voice channel so friends can see you’re around and pop in to talk without having to call. You can even watch videos together!•  Reliable tech for staying close with friends. Low-latency voice and video chat feels like you’re meeting in the same room.•  Easily talk with friends while gaming and steam roll the competition.•  Be a meme messenger with easy image sharing STAY CLOSE WITH TEXT, VIDEO, AND VOICE CHAT•  Wave hello over video, watch friends stream their games, share stories over voice calls, or gather up and have a drawing session with screen share.•  Snap a photo and turn it into your own custom emojis and share them with friends.•  Share anything from funny videos and stories to your latest group photos, and pin your favorites to remember those moments later.•  Hang out in group channels or talk privately with direct messages•  Zoom through convos with friends using topic-specific channels! FOR A FEW OR A FANDOM•  Custom moderation tools and permission levels can group up your friends or teams, organize meetings for your local book club, or bring together music fans from around the world.•  Create moderators, give special members access to private channels, and much more."
   },
   "badges":[
      {
         "name":"#1 top grossing communication"
      }
   ],
   "categories":[
      {
         "name":"Communication",
         "link":"https://play.google.com/store/apps/category/COMMUNICATION",
         "categoryId":"COMMUNICATION"
      }
   ],
   "updatedOn":"Oct 17, 2022",
   "dataSafety":[
      {
         "text":"This app may share these data types with third parties",
         "subtext":"Device or other IDs",
         "link":"No link"
      },
      ...and other data safety info
   ],
   "whatsNew":{
      "snippet":"As always, we have made some bug fixes and improvements.Please checkout our in-app changelog via Settings -> \"Change Log\" for more detailed informationOr check out our Twitter: https://twitter.com/discord"
   },
   "reviews":[
      {
         "title":"Elphaba Fang (Nesissa)",
         "avatar":"https://play-lh.googleusercontent.com/a-/ACNPEu-7nG2DMYHSehZX_CHW53PNzz8us_3P39oZJ4iT3g=s64-rw",
         "rating":2,
         "snippet":"So, used to play D&D through discord, but after some of the more recent updates it's made it impossible to type up any encounters because the text won't scroll with the cursor and whatnot. Tried contacting the support team, and did everything they suggested. Nothing fixed. I loved this app, and if it wasn't the only way to keep in contact with so many of my friends I wouldn't use it as often.",
         "likes":30,
         "date":"October 18, 2022",
         "response":{
            "title":"Discord Inc.",
            "snippet":"We hear you, and our teams are actively working on rolling out fixes daily. If you continue to experience issues, please make sure your app is on the latest updated version and follow-up with our support. Additionally, your feedback greatly affects what we focus on, so please let us know if you continue to have issues at dis.gd/contact.",
            "date":"October 18, 2022"
         }
      },
      ...and other reviews
   ],
   "developerContact":{
      "website":"https://dis.gd/contact",
      "email":"support@discord.com",
      "address":"444 De Haro St #200, San Francisco, CA 94107, USA",
      "privacyPolicy":"https://discordapp.com/privacy/"
   },
   "similarApps":[
      {
         "categoryTitle":"Similar apps",
         "seeMoreLink":"https://play.google.com/store/apps/collection/cluster?gsr=SjBqGHA0U0N3U09xaTIyc29MNysvNk5RVkE9PcICEwoPCgtjb20uZGlzY29yZBAHGAg%3D:S:ANO1ljLD_aU",
         "items":[
            {
               "title":"Twitch: Live Game Streaming",
               "link":"https://play.google.com/store/apps/details?id=tv.twitch.android.app",
               "developer":"Twitch Interactive, Inc.",
               "rating":4.4,
               "thumbnail":"https://play-lh.googleusercontent.com/QLQzL-MXtxKEDlbhrQCDw-REiDsA9glUH4m16syfar_KVLRXlzOhN7tmAceiPerv4Jg=s128-rw",
               "appId":"tv.twitch.android.app"
            },
            ...and other apps
         ]
      }
   ]
}
```

<h2 id='serp_api'>Using<a href="https://serpapi.com/google-play-product-api"> Google Play Product API </a>from SerpApi</h2>

This section is to show the comparison between the DIY solution and our solution.

The biggest difference is that you don't need to create the parser from scratch and maintain it.

There's also a chance that the request might be blocked at some point from Google, we handle it on our backend so there's no need to figure out how to do it yourself or figure out which CAPTCHA, proxy provider to use.

First, we need to install [`google-search-results-nodejs`](https://www.npmjs.com/package/google-search-results-nodejs):

```bash
npm i google-search-results-nodejs
```

Here's the [full code example](https://replit.com/@MikhailZub/Google-Play-App-Info-with-NodeJS-SerpApi#withSerpApi.js), if you don't need an explanation:

```javascript
const SerpApi = require("google-search-results-nodejs");
const search = new SerpApi.GoogleSearch(process.env.API_KEY); //your API key from serpapi.com

const params = {
  engine: "google_play_product", // search engine
  gl: "us", // parameter defines the country to use for the Google search
  hl: "en", // parameter defines the language to use for the Google search
  store: "apps", // parameter defines the type of Google Play store
  product_id: "com.discord", // Parameter defines the ID of a product you want to get the results for.
};

const getJson = () => {
  return new Promise((resolve) => {
    search.json(params, resolve);
  });
};

const getResults = async () => {
  const json = await getJson();
  const {
    product_info,
    media,
    about_this_app,
    badges,
    categories,
    updated_on,
    data_safety,
    what_s_new,
    reviews,
    developer_contact,
    similar_results,
  } = json;
  return {
    product_info,
    media,
    about_this_app,
    badges,
    categories,
    updated_on,
    data_safety,
    what_s_new,
    reviews,
    developer_contact,
    similar_results,
  };
};

getResults().then((result) => console.dir(result, { depth: null }));
```

<h3 id='serp_api_code_explanation'>Code explanation</h3>

First, we need to declare `SerpApi` from [`google-search-results-nodejs`](https://www.npmjs.com/package/google-search-results-nodejs) library and define new `search` instance with your API key from [SerpApi](https://serpapi.com/manage-api-key):

```javascript
const SerpApi = require("google-search-results-nodejs");
const search = new SerpApi.GoogleSearch(API_KEY);
```

Next, we write the necessary parameters for making a request:

```javascript
const params = {
  engine: "google_play_product", // search engine
  gl: "us", // parameter defines the country to use for the Google search
  hl: "en", // parameter defines the language to use for the Google search
  store: "apps", // parameter defines the type of Google Play store
  product_id: "com.discord", // Parameter defines the ID of a product you want to get the results for.
};
```

Next, we wrap the search method from the SerpApi library in a promise to further work with the search results:

```javascript
const getJson = () => {
  return new Promise((resolve) => {
    search.json(params, resolve);
  });
};
```

And finally, we declare the function `getResult` that gets data from the page and return it:

```javascript
const getResults = async () => {
  ...
};
```

In this function, we get `json` with results, then we need to [destructure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) and then return all that we need from received `json`:

```javascript
const json = await getJson();
const { product_info, media, about_this_app, badges, categories, updated_on, data_safety, what_s_new, reviews, developer_contact, similar_results } =
  json;
return {
  product_info,
  media,
  about_this_app,
  badges,
  categories,
  updated_on,
  data_safety,
  what_s_new,
  reviews,
  developer_contact,
  similar_results,
};
```

After, we run the `getResults` function and print all the received information in the console with the [`console.dir`](https://nodejs.org/api/console.html#consoledirobj-options) method, which allows you to use an object with the necessary parameters to change default output options:

```javascript
getResults().then((result) => console.dir(result, { depth: null }));
```

<h2 id='serp_api_output'>Output</h2>

```json
{
   "product_info":{
      "title":"Discord: Talk, Chat & Hang Out",
      "authors":[
         {
            "name":"Discord Inc.",
            "link":"https://play.google.com/store/apps/developer?id=Discord+Inc."
         }
      ],
      "extensions":[
         "In-app purchases"
      ],
      "rating":4.1,
      "reviews":4760000,
      "content_rating":{
         "text":"Teen",
         "thumbnail":"https://play-lh.googleusercontent.com/mw_NfsvKM8m6RPv8Fz2GQawCOsqWv010saMnc7zbWalMxuaA9IY8h7E0VMieLxSxAFB98NFeYqbFrXXq=w48-h16-rw"
      },
      "downloads":"100M+",
      "thumbnail":"https://play-lh.googleusercontent.com/0oO5sAneb9lJP6l8c6DH4aj6f85qNpplQVHmPmbbBxAukDnlO7DarDW0b-kEIHa8SQ=w240-h480-rw",
      "offers":[
         {
            "text":"Install",
            "link":"https://play.google.com/store/apps/details?id=com.discord&rdid=com.discord&feature=md&offerId"
         }
      ]
   },
   "media":{
      "video":{
         "thumbnail":"https://i.ytimg.com/vi/XoCvEM0Ah6E/hqdefault.jpg",
         "link":"https://play.google.com/video/lava/web/player/yt:movie:XoCvEM0Ah6E?autoplay=1&embed=play"
      },
      "images":[
         "https://play-lh.googleusercontent.com/85W8SSlu7z62P5uqatGOxdhX8JJJ7c_p11I_982xaPxMptsE9z4QeZr78Ua_E7A8OQ=w526-h296-rw",
         ...and other images
      ]
   },
   "about_this_app":{
      "snippet":"Discord is where you can make a home for your communities and friends. Where you can stay close and have fun over text, voice, and video chat. Whether you’re part of a school club, a gaming group, a worldwide art community, or just a handful of friends who want to spend time together, Discord makes it easy to talk every day, and hang out more often.CREATE AN INVITE-ONLY PLACE• Discord servers are organized into topic-based channels where you can collaborate, share, have meetings, or just talk to friends about your day without clogging up a group chat.• Send a message directly to a friend or call them up with our voice chat feature• Voice channels make hanging out easy. Got a free moment? Grab a seat in a voice channel so friends can see you’re around and pop in to talk without having to call. You can even watch videos together!• Reliable tech for staying close with friends. Low-latency voice and video chat feels like you’re meeting in the same room.• Easily talk with friends while gaming and steam roll the competition.• Be a meme messenger with easy image sharing STAY CLOSE WITH TEXT, VIDEO, AND VOICE CHAT• Wave hello over video, watch friends stream their games, share stories over voice calls, or gather up and have a drawing session with screen share.• Snap a photo and turn it into your own custom emojis and share them with friends.• Share anything from funny videos and stories to your latest group photos, and pin your favorites to remember those moments later.• Hang out in group channels or talk privately with direct messages• Zoom through convos with friends using topic-specific channels! FOR A FEW OR A FANDOM• Custom moderation tools and permission levels can group up your friends or teams, organize meetings for your local book club, or bring together music fans from around the world.• Create moderators, give special members access to private channels, and much more."
   },
   "badges":[
      {
         "name":"#1 top grossing communication"
      }
   ],
   "categories":[
      {
         "name":"Communication",
         "link":"https://play.google.com/store/apps/category/COMMUNICATION",
         "category_id":"COMMUNICATION",
         "serpapi_link":"https://serpapi.com/search.json?apps_category=COMMUNICATION&engine=google_play&gl=us&hl=en&store=apps"
      }
   ],
   "updated_on":"Oct 17, 2022",
   "data_safety":[
      {
         "text":"This app may share these data types with third parties",
         "subtext":"Device or other IDs"
      },
      ...and other data safety info
   ],
   "what_s_new":{
      "snippet":"As always, we have made some bug fixes and improvements.Please checkout our in-app changelog via Settings -> \"Change Log\" for more detailed informationOr check out our Twitter: https://twitter.com/discord"
   },
   "reviews":[
      {
         "title":"Elphaba Fang (Nesissa)",
         "avatar":"https://play-lh.googleusercontent.com/a-/ACNPEu-7nG2DMYHSehZX_CHW53PNzz8us_3P39oZJ4iT3g",
         "rating":2,
         "snippet":"So, used to play D&D through discord, but after some of the more recent updates it's made it impossible to type up any encounters because the text won't scroll with the cursor and whatnot. Tried contacting the support team, and did everything they suggested. Nothing fixed. I loved this app, and if it wasn't the only way to keep in contact with so many of my friends I wouldn't use it as often.",
         "likes":34,
         "date":"October 18, 2022",
         "response":{
            "title":"Discord Inc.",
            "snippet":"We hear you, and our teams are actively working on rolling out fixes daily. If you continue to experience issues, please make sure your app is on the latest updated version and follow-up with our support. Additionally, your feedback greatly affects what we focus on, so please let us know if you continue to have issues at dis.gd/contact.",
            "date":"October 18, 2022"
         }
      },
      ...and other reviews
   ],
   "developer_contact":{
      "website":"https://dis.gd/contact",
      "email":"support@discord.com",
      "address":"444 De Haro St #200, San Francisco, CA 94107, USA",
      "privacy_policy":"https://discordapp.com/privacy/"
   },
   "similar_results":[
      {
         "title":"Similar apps",
         "see_more_link":"https://play.google.com/store/apps/collection/cluster?gsr=SjBqGEd2MDZGRy8yYkg5Y2JxOTY1NTlFSGc9PcICEwoPCgtjb20uZGlzY29yZBAHGAg%3D:S:ANO1ljIP9ug",
         "see_more_token":"SjBqGEd2MDZGRy8yYkg5Y2JxOTY1NTlFSGc9PcICEwoPCgtjb20uZGlzY29yZBAHGAg%3D:S:ANO1ljIP9ug",
         "serpapi_link":"https://serpapi.com/search.json?engine=google_play&gl=us&hl=en&see_more_token=SjBqGEd2MDZGRy8yYkg5Y2JxOTY1NTlFSGc9PcICEwoPCgtjb20uZGlzY29yZBAHGAg%253D%3AS%3AANO1ljIP9ug&store=apps",
         "items":[
            {
               "title":"Twitch: Live Game Streaming",
               "link":"https://play.google.com/store/apps/details?id=tv.twitch.android.app",
               "product_id":"tv.twitch.android.app",
               "serpapi_link":"https://serpapi.com/search.json?engine=google_play_product&gl=us&hl=en&product_id=tv.twitch.android.app&store=apps",
               "rating":4.4,
               "extension":[
                  "Twitch Interactive, Inc."
               ],
               "thumbnail":"https://play-lh.googleusercontent.com/QLQzL-MXtxKEDlbhrQCDw-REiDsA9glUH4m16syfar_KVLRXlzOhN7tmAceiPerv4Jg=s64-rw"
            },
            ...and other apps
         ]
      }
   ]
}
```

<h2 id='links'>Links</h2>

- [Code in the online IDE](https://replit.com/@MikhailZub/Google-Play-App-Info-with-NodeJS-SerpApi#index.js)
- [Google Play Product API](https://serpapi.com/google-play-product-api)

If you want to see some projects made with SerpApi, [write me a message](mailto:miha01012019@gmail.com).

---

<p style="text-align: center;">Join us on <a href="https://twitter.com/serp_api">Twitter</a> | <a href="https://www.youtube.com/channel/UCUgIHlYBOD3yA3yDIRhg_mg">YouTube</a></p>
<p style="text-align: center;">Add a  <a href="https://github.com/serpapi/public-roadmap/issues">Feature Request</a>💫 or a <a href="https://github.com/serpapi/public-roadmap/issues">Bug</a>🐞</p>