How to Scrape Google Ad Library Ads with Rust

Extract ads data from Google Ad Library

🦀 Using Rust

Overview

Learn how to scrape Google Ad Library ads using Rust. This comprehensive guide will walk you through the entire process, from setup to implementation.

What You'll Learn

  • • Setting up your development environment
  • • Installing the required HTTP client
  • • Authenticating with the ScrapeCreators API
  • • Making requests to Google Ad Library
  • • Handling responses and errors
  • • Best practices for production use

What You'll Get

  • • Access to ads data
  • • JSON formatted responses
  • • Real-time data access
  • • Scalable solution
  • • Error handling patterns
  • • Performance optimization tips

Prerequisites

1. API Key

First, you'll need a ScrapeCreators API key to authenticate your requests.

Sign up at app.scrapecreators.com to get your free API key with 100 requests.

2. Development Environment

Make sure you have the following installed:

  • Rust and its dependencies
  • • A code editor (VS Code, Sublime, etc.)
  • • Basic understanding of API requests
  • • Command line interface access

Step 1: Install HTTP Client

Reqwest is a high-level HTTP client for Rust

cargo
cargo add reqwest

Step 2: API Implementation

Now let's make a request to the Google Ad Library API using Rust. Replace YOUR_API_KEY with your actual API key.

Rust
use reqwest;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = scrape().await?;
println!("Response: {}", result);
Ok(())
}

async fn scrape() -> Result<String, Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
// Build query parameters
let mut params = HashMap::new();
params.insert("domain".to_string(), "lululemon.com".to_string());
params.insert("advertiser_id".to_string(), "AR01614014350098432001".to_string());
params.insert("topic".to_string(), "all".to_string());
params.insert("region".to_string(), "US".to_string());
params.insert("cursor".to_string(), "CgoAP7znOo9RPjf%2FEhD5utgx8m75NrTTbU0AAAAAGgn8%2BJyW%2BJQK40A%3D".to_string());
let response = client
.get("https://api.scrapecreators.com/v1/google/company/ads")
.header("x-api-key", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.query(&params)
.send()
.await?;
if response.status().is_success() {
let body = response.text().await?;
Ok(body)
} else {
Err(format!("HTTP {}: {}", response.status(), response.text().await?).into())
}
}

Step 3: Testing Your Code

API Parameters

This endpoint accepts the following parameters:

domainOptional(string)

The domain of the company

Example: lululemon.com

advertiser_idOptional(string)

The advertiser id of the company

Example: AR01614014350098432001

topicOptional(select)

The topic to search for. If you search for 'political', you will also need to pass a 'region', like 'US' or 'AU'

Example: all

regionOptional(string)

The region to search for. Defaults to anywhere

Example: US

cursorOptional(string)

Cursor to paginate through results

Example: CgoAP7znOo9RPjf%2FEhD5utgx8m75NrTTbU0AAAAAGgn8%2BJyW%2BJQK40A%3D

Run Your Code

Execute your script to test the API connection. You should see a JSON response with Google Ad Library ads data.

✅ Success: You should receive a structured JSON response containing the requested data.

Expected Response

Here's an example of the JSON response you'll receive:

Sample Response
{
"ads": [
{
"advertiserId": "AR10397446976948928513",
"creativeId": "CR00429437544950661121",
"firstShown": "2025-06-28T00:00:00.000Z",
"lastShown": "2025-08-11T23:46:18.000Z",
"format": "text",
"overallImpressions": {
"min": null,
"max": null
},
"creativeRegions": [
{
"regionCode": "FI",
"regionName": "Finland"
}
],
"regionStats": [
{
"regionCode": "FI",
"regionName": "Finland",
"firstShown": "2025-06-30T00:00:00.000Z",
"lastShown": "2025-08-11T00:00:00.000Z",
"impressions": {},
"platformImpressions": []
}
],
"variations": [
{
"destinationUrl": "www.scrapingbee.com/",
"headline": "Switch to #1 Web Scraping API",
"description": "ScrapingBee API handles rotating proxies, headless browsers and CAPTCHAS."
}
]
},

Verify Response Structure

Check that your response includes the expected fields:

  • ads(object)
  • cursor(string)
  • success(boolean)
  • statusCode(number)

Best Practices

1

Error Handling

Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.

2

Caching

Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.

3

Security

Never expose your API key in client-side code. Use environment variables and secure key management practices.

Performance Tips

Batch Requests

When scraping multiple ads, consider batching requests to maximize throughput while staying within rate limits.

Async Processing

Use asynchronous processing in Rust to handle multiple requests concurrently and improve overall performance.

Common Use Cases

Market Research

Analyze Google Ad Library ads to understand market trends, competitor analysis, and audience insights.

Content Analytics

Track performance metrics, engagement rates, and content trends across Google Ad Library ads.

Lead Generation

Identify potential customers and business opportunities throughGoogle Ad Library data analysis.

Troubleshooting

Common Errors

401 Unauthorized

Check your API key is correct and properly formatted in the x-api-key header.

402 Payment Required

You ran out of credits and need to buy more.

404 Not Found

The resource might not exist or be private.

500 Server Error

Temporary server issue. Implement retry logic with exponential backoff.

Frequently Asked Questions

How much does it cost to scrape Google Ad Library ads?

ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.

Is it legal to scrape Google Ad Library data?

Scraping publicly available data is fair game, and we only collect public data. So anything that you can see in an incognito browser is what we collect.

How fast can I scrape Google Ad Library ads?

There is no rate limit! So you can scrape as fast as you want!

What data format does the API return?

All API responses are returned in JSON format, making it easy to integrate with any programming language or application.

Can I use this with other Rust frameworks?

Yes! This tutorial focuses on core Rust HTTP concepts that work with any framework. The API calls remain the same regardless of your specific Rust setup.

How do I handle large datasets?

For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.

Related Tutorials

Ready to Start Scraping?

Get started with 100 free API calls. No credit card required.