faniAhmed / GoogleAdsTransparencyScraper

13 stars 9 forks source link

Number of creatives #7

Open WebdevWebi opened 6 days ago

WebdevWebi commented 6 days ago

I am working with your project, and I have implemented a script whose code I will provide you:

from GoogleAds.main import GoogleAds, show_regions_list

def main():
    # Creazione dell'istanza GoogleAds
    google_ads = GoogleAds(region="IT")

    # Passo 1: Inserisci la parola chiave
    keyword = input("Inserisci la parola chiave per cercare inserzionisti: ")
    print(f"\nCerco inserzionisti per la parola chiave: {keyword}...")

    # Ottieni suggerimenti di ricerca
    suggestions = google_ads.get_all_search_suggestions(keyword)
    if not suggestions:
        print(f"Nessun suggerimento trovato per la parola chiave '{keyword}'.")
        return

    # Filtra i suggerimenti per estrarre inserzionisti
    advertisers = []
    for suggestion in suggestions:
        for _, details in suggestion.items():
            if "1" in details and "2" in details:  # Controllo per identificare inserzionisti
                advertisers.append({
                    "name": details["1"],  # Nome dell'inserzionista
                    "id": details["2"],    # ID dell'inserzionista
                    "region": details.get("3", "Unknown Region"),  # Regione, se disponibile
                })

    if not advertisers:
        print("Nessun inserzionista trovato nei suggerimenti.")
        return

    # Mostra lista degli inserzionisti
    print("\nInserzionisti trovati:")
    for idx, advertiser in enumerate(advertisers, start=1):
        print(f"{idx}. {advertiser['name']} (ID: {advertiser['id']}, Regione: {advertiser['region']})")

    # Seleziona inserzionista
    try:
        selection = int(input("\nSeleziona un inserzionista (numero): "))
        if 1 <= selection <= len(advertisers):
            selected_advertiser = advertisers[selection - 1]
        else:
            print("Selezione non valida. Esco.")
            return
    except ValueError:
        print("Input non valido. Esco.")
        return

    advertiser_id = selected_advertiser["id"]
    print(f"\nHai selezionato: {selected_advertiser['name']} (ID: {advertiser_id}, Regione: {selected_advertiser['region']})")

    # Passo 2: Ottieni lista delle creatività
    creatives_info = google_ads.creative_search_by_advertiser_id(advertiser_id, 200)
    if not creatives_info:
        print("Nessuna creatività trovata per l'inserzionista selezionato.")
        return

    # Creatività restituite come lista
    print("\nCreatività trovate per l'inserzionista selezionato:")
    for idx, creative in enumerate(creatives_info, start=1):
        print(f"{idx}. {creative}")

    # Seleziona creatività
    try:
        selection = int(input("\nSeleziona la creatività (numero): "))
        if 1 <= selection <= len(creatives_info):
            specific_creative_id = creatives_info[selection - 1]
        else:
            print("Selezione non valida. Esco.")
            return
    except ValueError:
        print("Input non valido. Esco.")
        return

    # Passo 3: Ottieni dettagli della creatività selezionata
    print(f"\nRecupero dettagli per la creatività ID: {specific_creative_id}...")
    ad_details = google_ads.get_detailed_ad(advertiser_id, specific_creative_id)

    # Mostra dettagli della creatività
    print("\nDettagli della creatività selezionata:")
    for key, value in ad_details.items():
        print(f"{key}: {value}")

if __name__ == "__main__":
    main()

However, I noticed that when carrying out a keyword search, advertisers are always scanned well, while the number of adverts relating to any previously scanned advertiser is not scanned well.

EXAMPLE: If an advertiser has 9 ads, only 3 are scanned.

I couldn't find a solution to this problem. Could you help me? Thanks!

faniAhmed commented 5 days ago

Can you provide a bit more detail with examples of what you are saying. Also, how I can recreate the problem, i.e which input are you using. Also, if you think there can be any improvement in the module you can contribute to it's development too.

WebdevWebi commented 5 days ago

Yes, sorry, I translated the script from Italian to English:

from GoogleAds.main import GoogleAds, show_regions_list

def main():
    # Creation of the GoogleAds instance
    google_ads = GoogleAds(region="IT")

    # Step 1: Enter your keyword
    keyword = input("Enter the keyword to search for advertisers: ")
    print(f"\nI am looking for advertisers for the keyword: {keyword}...")

    # Get search suggestions
    suggestions = google_ads.get_all_search_suggestions(keyword)
    if not suggestions:
        print(f"No suggestions found for the keyword '{keyword}'.")
        return

    # Filter suggestions to extract advertisers
    advertisers = []
    for suggestion in suggestions:
        for _, details in suggestion.items():
            if "1" in details and "2" in details:  # Controllo per identificare inserzionisti
                advertisers.append({
                    "name": details["1"],  # Nome dell'inserzionista
                    "id": details["2"],    # ID dell'inserzionista
                    "region": details.get("3", "Unknown Region"),  # Regione, se disponibile
                })

    if not advertisers:
        print("No advertisers found in suggestions.")
        return

    # Show list of advertisers
    print("\nAdvertisers found:")
    for idx, advertiser in enumerate(advertisers, start=1):
        print(f"{idx}. {advertiser['name']} (ID: {advertiser['id']}, Region: {advertiser['region']})")

    # Select advertiser
    try:
        selection = int(input("\nSelect an advertiser (number): "))
        if 1 <= selection <= len(advertisers):
            selected_advertiser = advertisers[selection - 1]
        else:
            print("Invalid selection. I go out.")
            return
    except ValueError:
        print("Invalid input. I go out.")
        return

    advertiser_id = selected_advertiser["id"]
    print(f"\nYou have selected: {selected_advertiser['name']} (ID: {advertiser_id}, Region: {selected_advertiser['region']})")

    # Step 2: Get creative list
    creatives_info = google_ads.creative_search_by_advertiser_id(advertiser_id, 200)
    if not creatives_info:
        print("No creatives found for the selected advertiser.")
        return

    # Creatives returned as a list
    print("\nCreatives found for the selected advertiser:")
    for idx, creative in enumerate(creatives_info, start=1):
        print(f"{idx}. {creative}")

    # Select creative
    try:
        selection = int(input("\nSelect creative (number): "))
        if 1 <= selection <= len(creatives_info):
            specific_creative_id = creatives_info[selection - 1]
        else:
            print("Invalid selection. I go out.")
            return
    except ValueError:
        print("Invalid input. I go out.")
        return

    # Step 3: Get details of the selected creative
    print(f"\nRetrieving details for the ID creative: {specific_creative_id}...")
    ad_details = google_ads.get_detailed_ad(advertiser_id, specific_creative_id)

    # Show creative details
    print("\nDetails of the selected creative:")
    for key, value in ad_details.items():
        print(f"{key}: {value}")

if __name__ == "__main__":
    main()

Now I'll show you the output that I receive and the output that Google receives for the same searched keyword:

my output: Screenshot 2024-11-22 090758

Google outputs: Screenshot 2024-11-22 091004 Screenshot 2024-11-22 090857

As you can see in my output only 2 adverts are detected, while Google's output detects many more adverts.

my input is "paper", a simple Italian test word, but I also detected this inconsistency with other keywords.