Flipkart Price API with Google Apps Script

Published in: Flipkart - Google Apps Script

Flipkart, the popular shopping website in India that sells everything from erasers to televisions, offers no API and therefore if you were to extract the pricing information of any Flipkart product, screen scraping is the only alternative.

Flipkart stores the pricing data inside <meta> tags with “itemprop” set to “price” and it is thus relatively easy to pull this information for the price tracker tool.

Here’s the Google Apps Script code that extracts the price details, item title and the thumbnail image given the URL of the product page using Regular Expressions. You can easily use this in combination with HTMLService  to create an API that returns pricing data for Flipkart product as JSON or XML.

function priceFlipkart(url) {

  if (url !== "") {

    try {

      /* Extract the HTML source of the Flipkart Page */
      var page = UrlFetchApp.fetch(url).getContentText();

      /* Regular Expression to extract Price from the META tag */
      var regex = /<meta[^>]*itemprop\s*=\s*"price"\s*content\s*=\s*"([^"]*)"/gi;

      if ((price = regex.exec(page)) !== null) {

        regex = /<meta[^>]*name\s*=\s*"og_title".*content\s*=\s*"([^"]*)/gi;
        title = regex.exec(page);

        /* We are using Canonical URL as it containes no tracking parameters */
        regex = /<meta[^>]*name\s*=\s*"og_url".*content\s*=\s*"([^"]*)/gi;
        canonical = regex.exec(page);

        /* The thumbnail image of the Flipkart Product */
        regex = /<meta[^>]*name\s*=\s*"og_image".*content\s*=\s*"([^"]*)/gi;
        image = regex.exec(page);

        if (title && canonical && image) {
          Logger.log(title[1] + "|" + image[1] + "|" + price[1]);
        } else {
          Logger.log("Could not fetch " + url);
    } catch (e) {
      Logger.log("Flipkart Error: " + e.toString());
📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Flipkart - Google Apps Script

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube