This blog was initially posted to Crawlbase Blog
Google Ads is a competitive space where you bid for visibility. To win, looking at your competitor’s ads can give you insights into their strategy, top performing keywords, and ad placements. By knowing what works for them, you can refine your campaigns and maximise return on investment (ROI).
In this guide we’ll cover why competitor analysis in Google Ads is important, what data to extract, and the best tools for it. We’ll also show you how to extract Google Ads data with the Crawlbase Crawling API.
Let’s get started!
How to Extract Competitor Google Ads Data
To analyze competitor Google Ads, you can extract ad data directly from Google search results using web scraping. In this section, we will show you how to set up the environment and write a Google Ads scraper using the Crawlbase Crawling API.
Setting Up Environment
Before writing the scraper, ensure you have the following:
- Python Installed – If you haven’t installed Python, download it from python.org.
- Crawlbase API Key – Sign up at Crawlbase to get your API token.
- Required Libraries – Install the necessary Python packages using:
pip install crawlbase
Writing the Google Ads Scraper Script
Now, let's write a simple Python script to extract Google Ads data from search results.
from crawlbase import CrawlingAPI
import json
# Initialize Crawlbase API
crawling_api = CrawlingAPI({'token': 'CRAWLBASE_NORMAL_TOKEN'})
def scrape_google_ads(query):
url = f"https://www.google.com/search?q={query}"
options = {'scraper': 'google-serp'}
response = crawling_api.get(url, options)
if response['headers']['pc_status'] == '200':
response_data = json.loads(response['body'].decode('latin1'))
ads = response_data.get('body', {}).get('ads', [])
return ads
else:
print("Failed to fetch data.")
return []
def save_to_json(data, filename):
with open(filename, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
print(f"Data saved to {filename}")
# Example usage
if __name__ == "__main__":
query = "samsung shops"
ads = scrape_google_ads(query)
if ads:
save_to_json(ads, "google_ads_data.json")
else:
print("No ads found.")
This script automates the process of scraping Google Ads using the Crawlbase Crawling API and its built-in Google SERP scraper. The scraper handles JavaScript rendering and bypasses Google’s anti-bot measures to give you structured ad data.
How This Script Works
- It sends a search request to Google using the Crawlbase Crawling API.
- It extracts Google Ads (including headlines, descriptions, and landing page URLs).
- It saves the data in a JSON file for easy analysis.
Save the above script in a file name “google_ads_scraper.py” and run the script using the following command:
python google_ads_scraper.py
You will see an output similar to the one below in the output JSON file.
[
{
"position": 1,
"title": "Official Online eShop | Amazing Offers On Smartphones",
"description": "Get Wide Range Of Samsung Products At Reasonable Price. Shop Now! Best Value Deals. Genuine Products. Cash On Delivery. Samsung Official Shop. Secured Payments.",
"url": "https://www.samsung.com/in/offer/",
"siteLinks": [
{
"title": "Samsung Galaxy M Series",
"description": "Starting From INR 7,990. Ultra Wide Dual Camera, Slim Design",
"url": "https://www.samsung.com/in/microsite/galaxy-m/sale/"
},
{
"title": "Samsung Galaxy A Series",
"description": "15W Fast Charging. Super AMOLED Infinity-U Display",
"url": "https://www.samsung.com/in/smartphones/galaxy-a/"
}
]
}
]
This blog was initially posted to Crawlbase Blog
Top comments (0)