Google Ads is part of the advertising world, especially for those who create and craft digital marketing strategies. Every time we look up a term on Google, we are prone to find ad results with their titles, descriptions, links, and other information.
What if we could extract this information massively with one click? I want to share this resource with you today. This resource will save you valuable time if you wish to create a Google Ads campaign or develop a competitive analysis.
Why this kind of resource is useful for a competitive analysis?
- Efficiency: This automation eliminates manual data collection, saving time and resources for creating your marketing strategy.
- Scalability: You can fetch SERP data from Google Ads in seconds to get many results for an extensive list of keywords.
- Accuracy: This automation ensures accurate data retrieval, helping you focus on other activities that require more thinking.
- Real-Time Insights: SEO or marketing professionals can get real-time insights from Google AdsSERP data, enabling them to adapt quickly to changes on Google.
- The resource works as keyword research: Identifying ads triggered by specific keywords gives valuable insight to enhance your strategy.
How does the code work?
You’ll need to copy and paste this code on Google Colab. But first, you must create an account on the website https://serpapi.com/, where you’ll get an API Key to use in the params dictionary.
To make it easier, you can follow the steps in this article, where I walk you through the process of creating the account and getting the API.
# Import necessary libraries
from serpapi import GoogleSearch
import pandas as pd
# Define parameters for Google Search API request
params = {
"location": "Bogotá, Colombia",
"hl": "es",
"gl": "co",
"api_key": your_api_key
}
# Define keywords for which ads will be extracted
keywords = ['aprender ingles', 'cursos de ingles', 'cursos de ingles bogota', 'cursos de ingles medellin', 'mejores cursos de ingles', 'cursos de ingles en cali', 'cursos de ingles para niños']
# Initialize empty list to store data
bulk_data = []
# Fetch search results for each keyword
for keyword in keywords:
params['q'] = keyword
search = GoogleSearch(params)
results = search.get_dict()
bulk_data.append(results)
# Define snippets to extract from ads
snippets = ['block_position','position','title','link', 'description', 'displayed_link', 'sitelinks']
ads_list = []
# Extract ads data for each keyword
for data, keyword in zip(bulk_data, keywords):
ads = data.get('ads', {})
for ad in ads:
new_dict_ads = {snippet: ad.get(snippet, None) for snippet in snippets}
new_dict_ads['consulta'] = keyword
ads_list.append(new_dict_ads)
# Create DataFrame from extracted ads data
df = pd.DataFrame(ads_list)
What is this code doing?
- Imports: Import necessary libraries:
serpapi
for interacting with the SERP API andpandas
for data manipulation. - Parameters: Define parameters for the Google Search API request, including location, language, country, and API key.
- Keywords: Specify a list of keywords for which you want to extract Google Ads from SERPs.
- Data Storage: Initialize an empty list to store the fetched search results for each keyword.
- Fetching Results: Iterate through each keyword, fetch search results using the GoogleSearch object, and append results to the storage list.
- Ad Snippets: Define snippets of information to extract from each ad and initialize an empty list to store the extracted ad data.
- Extracting Ads: Iterate through the fetched search results, extract ad data for each keyword, create dictionaries containing ad information, and append them to the ads list.
- DataFrame Creation: Use pandas to create a DataFrame from the extracted ads data for further analysis.
- Using in Google Colab: Copy the code into a Google Colab code cell, run it, and access the DataFrame (
df
) containing the extracted Google Ads data for analysis or export.
How does the output look?
After fetching the information and extracting the required terms, you’ll get a data frame with the results, which are sorted by keyword. This allows you to see which results correspond to which keyword.
Finally, exporting those results to Google Sheets or Excel will be handy, especially if you want to manipulate the data and combine it with other marketing analysis output.
from google.colab import files
file_path = '/content/ads-soliplast.csv'
df.to_csv(file_path, index=False)
files.download(file_path)
I am a skilled and self-motivated marketing and SEO professional with 11+ years of experience in different digital marketing areas: content planning, information architecture, and primarily creating, leading, and tracking SEO strategies. In the last six years, I have specialized my career in developing processes to redesign and launch websites successfully using Hubspot’s Growth-Driven Design methodology.
Leave a Reply