If you're interested in using SerpApi to collect data from search engines like Google SERP, Google Shopping, YouTube, Bing, and more but don't know how to code, you're in the right place!
In this post, we'll show you our no-code solution using the Google Sheets Extension!
Video tutorial
Do you prefer to watch a video tutorial instead? Here we go
[Update] 100% No Code solution
If you want to use SerpApi 100% without code, you should try nocodeserpapi.com. No formula is needed; just fill and click, and you're done!
How to install SerpApi extension
Step 1:
Go to https://docs.google.com/spreadsheets/ and create a new spreadsheet
Step 2:
Click the Extensions menu, click Add ons, choose "Get add-ons"
Step 3:
Search for "serpapi", then click the SerpApi extension from serpapi,llc.
Step 4: Click the install button
Step 5:
Choose your Google account and allow permissions
*It will then ask you for the API key. See steps 6 and 7
Step 6:
If you haven't, register for free at serpapi.com and copy your API key from the dashboard
Step 7:
Add your API key to the input
Now, your spreadsheet is connected to SerpApi! We'll see how to perform a specific search and add the data to it!
How it works
- Our extension provides a function called
SEPRPAPI_RESULT(parameters)
which can be used as the Spreadsheets formula. (Don't worry; you can just copy and paste the text later!) - This function needs two parameters, Query and Selector. Query is the "command" or "search text" we want to perform, and Selector is the data we want to display on the cell.
Where to get the formula?
SerpApi provides a playground where you can use our API through a user interface.
Link: https://serpapi.com/playground?engine=google_news&gl=us
The best part is getting the code sample or a spreadsheet formula from this page. Click on the "Export to code" button in the top right corner and choose "Google sheets" from the "code to integrate" section:
Take a look at the "code to integrate" section.
This is the formulate that we want to copy and paste into one of the cells in Google Sheets.
See, there are two values between the (
and )
separated by a comma.
engine=google_news&gl=us
This is the "search" part of our parametersuggestions.0.value
This is the data that we want to display from the search
Example
We have many search engine APIs that you can use:
In this sample, let's get some data from Google search results to our Spreadsheet using Google Search API.
Step 1: Search in the playground
Visit the playground page: https://serpapi.com/playground
By default, we're using Google. If search API, if you want to use another, search engine click in the top left corner.
Feel free to change the "search query" to any query you want. You can also adjust other data like geographic location, google domain and so on. After you are satisfied with the settings, click the blue search button to see the result.
Step 2: Copy and paste the formula in Excel
Now you can export the formula from this:
paste it into your spreadsheet. Select any cell you want and paste the formula there.
You'll see an error. That is expected!
Step 3: Adjust the value
The error we see above is because we haven't defined which data we want to display on the cell, which should be in the second parameter for the formula.
Back to the playground, after clicking on the search button, we should see this result:
- The first one is the search results sample.
- The second one is "JSON results".
What is JSON?
JSON is a data format that is commonly used. Here is more about JSON:
Show specific data from JSON
By looking at this JSON data, we can start building the value for the second parameter we need.
To help us with this, you can start by clicking any item in the "search results" section (in the previous playground). For example, if I'm scrolling to the top ranking results and clicking on one of the results:
The right section (JSON result) will scroll to the related JSON section.
If I want to get the title of this item, the way I can fill the second parameter in the formula is by: organic_results.0.title
Explanation
- All items are wrapped in the organic_results
key, that's why we need to use it first.
- We have many items in the organic_results
. We call this an array (think of an array like a box where we can store many items).
- The array starts from 0 (zero) in the programming world. So, to get the first item, we need to write organic_results.0
- Finally, to get a specific result on this "item," I'll add a key name on the red text on the left side of the screenshot above.
organic_results.0.title
for the title.organic_results.0.snippet
for the snippet.- and so on
Display data from dynamic value
If we want to display the next result, then we need to increase the 0 value before, organic_results.1.title
, organic_results.2.title
, and so on for the next results.
Luckily we can automate this process.
Step 1: Create a number list
I create the index number on the first column from 0-5 (feel free to adjust), remember the index starts from 0.
Step 2: Adjust the formula
Now, assume we want to display the value on the B2 cell, we will paste the previous formula to the B2 section but with this adjustment:
=SERPAPI_RESULT("engine=google&q=keyboard&location=Austin, Texas, United States&google_domain=google.com&gl=us&hl=en", "organic_results."&A2&".title")
Here is the screenshot:
The way we concat a text with value from the cell is by adding "&CELL&"
in this case "&A2&"
since the number 0 is in the cell A2.
Now, we can drag the blue point on the corner of the cell to automatically fill the index.
Step 3: Get other value
If we want to get the other value, we can change the last part of the parameter from .title
to any field we want. For example, if I want to display snippet
results on the C cell.
I'm adding this formula to c2 cell:
=SERPAPI_RESULT("engine=google&q=keyboard&location=Austin, Texas, United States&google_domain=google.com&gl=us&hl=en", "organic_results."&A2&".snippet")
And drag the blue points just like the previous part.
Thank you for reading this post! That's how to get a search engine result in Google Sheets. Feel free to contact us at contact@serpapi.com
if you have any questions.
More Resources
Here are other use cases where you can use our Google Sheets Extension: