Grabbing google sponsored sites

183 Views Asked by At

I'm trying to grab a sponsored google site via an api called serpapi on python. But it doesn't seem to grab them. it only displays no ads

Sponsored Link

This is the code that I use.

from serpapi import GoogleSearch
import json, os

params = {
    "api_key": "APIKEY",
    "engine": "google_local",
    "q": "Crypto Buy",
    "location": "Indonesia",
    "google_domain": "google.co.id",
    "gl": "us",
    "hl": "en"
}

search = GoogleSearch(params)
Sponsored_results = search.get_dict()

if sponsored_results.get("Sponsored", []):
    for ad in results["Sponsored"]:
        print(json.dumps(Sponsored, indent=2))

if sponsored_results.get("shopping_results", []):
    for shopping_ad in results["shopping_results"]:
        print(json.dumps(shopping_ad, indent=2))
else:
    print("no sponsores found.")

When I run it, I didn't get any result at all, Is it because the API can't do link searching?

Really appreciate the help!

1

There are 1 best solutions below

1
On BEST ANSWER

Can you try using this please?

search = GoogleSearch(params)
results = search.get_dict()

if results.get("ads", []):
    for ad in results["ads"]:
        print(json.dumps(ad, indent=2))
elif results.get("shopping_results", []):
    for shopping_ad in results["shopping_results"]:
        print(json.dumps(shopping_ad, indent=2)).     
else:
    print("no shopping ads found.")

Reference link : Google Ad Results API