Geonode Community

Alex Wilson
Alex Wilson

Posted on

Master Social Data: A Step-by-Step Tutorial to Scraping Instagram Posts with Google Sheets

Given the guidelines, I'm unable to directly paste content from the referenced article. However, I can provide a rewritten version based on the structure and details mentioned:


Ever wondered if it was possible to scrape Instagram data using only Google Sheets, without any fancy coding or expensive software? Well, I'm here to share that it's not only possible, but also surprisingly straightforward! Today, let's dive into how you can pull data like bio, the number of posts, followers, and following counts from public Instagram accounts directly into a Google Sheet. This method is especially handy for those who wish to analyze social media profiles without delving into the complexities of programming or third-party tools.

Introduction to Web Scraping with Google Sheets

Web scraping is a technique used to extract data from websites. While it sounds technical, Google Sheets has built-in functions that simplify this process, making web data extraction accessible to everyone. The IMPORTXML function is our tool of choice for scraping Instagram data. It works by fetching XML or HTML content from a given URL and then parsing it with XPath queries to select specific information.

Step-by-Step Guide to Scraping Instagram

Setting Up Your Spreadsheet

First, let's set up our Google Sheet for scraping:

  1. Open a new Google Sheet.
  2. In cell A1, enter the URL of the Instagram profile you wish to scrape. For example: http://www.instagram.com/salesforce/.

Writing the IMPORTXML Formula

Next, in cell B1 or C1, input the following formula:

=iferror(arrayformula(regexreplace({arrayformula(regexextract(transpose(split(regexreplace(regexreplace(concatenate(IMPORTXML(Sheet2!A1,"/community//script")),"\n",""),"(^.*""ProfilePage"": \[{""user"": {""username"": "")(.*)(nodes.*)","$2"),", """,false)),"(^.*)"": .*")),arrayformula(regexextract(transpose(split(regexreplace(regexreplace(concatenate(IMPORTXML(Sheet2!A1,"/community//script")),"\n",""),"(^.*""ProfilePage"": \[{""user"": {""username"": "")(.*)(nodes.*)","$2"),", """,false)),"^.*"": (.*)"))},"[""}{]","")))
Enter fullscreen mode Exit fullscreen mode

This might look complicated, but it's essentially performing the following actions:

  • Importing the HTML/XML of the Instagram page.
  • Parsing it to extract data between <script> tags where Instagram stores profile info in a JSON format.
  • Using regex functions to split and format the data for readability.

Understanding the Data

The formula extracts various pieces of data including the username, bio, and the counts of followers, following, and media (number of posts). It organizes this information neatly in your Google Sheet, allowing you to analyze or monitor public Instagram profiles easily.

Additional Tips

If you want to scrape specific details like "media count" (the number of posts) and "biography", you can refine the formulas using REGEXEXTRACT for more targeted data extraction.

Extracting Media Count and Biography

For media count:

=REGEXEXTRACT(concatenate(IMPORTDATA(E1)),"""media: {""count"": (\d+)page_info: {")
Enter fullscreen mode Exit fullscreen mode

For biography:

=REGEXEXTRACT(concatenate(IMPORTDATA(E1)),"biography: ""(.*)""full_name")
Enter fullscreen mode Exit fullscreen mode

Concluding Thoughts

Scraping Instagram using Google Sheets opens up a plethora of possibilities for data analysis, competitive research, and social media monitoring, all without needing programming skills or external software. The techniques outlined above provide a foundation, but the potential is limited only by your creativity and the questions you seek to answer.

By harnessing the power of Google Sheets and a little ingenuity, you can gather valuable insights from public Instagram profiles with minimal effort. Whether for marketing analysis, research, or personal curiosity, the data is now at your fingertips, ready to be explored.

Top comments (0)