Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
serpapi_scrape_google_shopping_ads
import os
from serpapi import GoogleSearch
# Search query parameters
params = {
"engine": "google",
"q": "cpu buy",
"api_key": os.getenv("API_KEY"),
}
search = GoogleSearch(params)
results = search.get_dict()
# Iterating over 'results' variable and calling for 'shopping_results'
for ad in results['shopping_results']: # For regular ads -> ['ads']
shopping_ad = ad['link'] # for regular ads -> ad['tracking_link']
print(shopping_ad)
# Output for Shopping Ads
'''
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABAGGgJxbg&sig=AOD64_33PWKS62wikXPnK4eK9W_J4_NJyg&ctype=5&q=&ved=2ahUKEwiw4O_QvcbwAhVDn-AKHS3fDp4Q5bgDegQIAhBY&adurl=
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABAEGgJxbg&sig=AOD64_2CN7ly9AFpd_Q-ASLkER0JQ_Ej3Q&ctype=5&q=&ved=2ahUKEwiw4O_QvcbwAhVDn-AKHS3fDp4Q5bgDegQIAhBk&adurl=
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABAFGgJxbg&sig=AOD64_3NrX-tM5IiDP0ad-8yx-y0UQOMdg&ctype=5&q=&ved=2ahUKEwiw4O_QvcbwAhVDn-AKHS3fDp4Q5bgDegQIAhBr&adurl=
'''
# Output for Regular Website Ads
'''
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABAPGgJxbg&sig=AOD64_16m1mZpLQgzRL9-jMXj0yfN5Ax1w&q&adurl
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABARGgJxbg&sig=AOD64_0UQiFSAv8MP7HI0rOy1ptzIpq4eQ&q&adurl
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABAOGgJxbg&sig=AOD64_3Afsek4QZb-kzvqyn7nzCsugoJhA&q&adurl
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABAKGgJxbg&sig=AOD64_2p1rLnHQ-Mq3JQFv7Dv6WI9SEZUw&q&adurl
https://www.google.com/aclk?sa=l&ai=DChcSEwiUtvfQvcbwAhUtBogJHWAOAOAYABAMGgJxbg&sig=AOD64_3Yy4jRu4o7J7lkpGyyr_nXJWnZaQ&q&adurl
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment