googleads-python-lib icon indicating copy to clipboard operation
googleads-python-lib copied to clipboard

Keyword_ideas setting keyword_text and Kse

Open steponafish opened this issue 7 years ago • 1 comments

I am having a bit of trouble with trying to add the KEYWORD_TEXT and SEARCH_VOLUME to variables. I am using the sample code from get_keyword_ideas.py and this is the part of the code that I am having trouble with:

# Display results.
    if 'entries' in page:
      keyword_list = []
      for result in page['entries']:
        attributes = {}
        for attribute in result['data']:
          print(attribute)
          attributes[attribute['key']] = getattr(attribute['value'], 'value', '0')
          kw = attributes['KEYWORD_TEXT']
          sv = attributes['SEARCH_VOLUME']
        #print ('Keyword with "%s" text and average monthly search volume '
        #       '"%s".'
        #       % (attributes['KEYWORD_TEXT'], attributes['SEARCH_VOLUME']))
        print(kw)
    else:
      print ('No related keywords were found.')

I am getting this error when trying to save them to variables:

sv undefined, attributes = {'KEYWORD_TEXT': 'seo'}
KeyError: 'SEARCH_VOLUME'
   args = ('SEARCH_VOLUME',)
   with_traceback = <built-in method with_traceback of KeyError object>

Since it's a list, I tried just going directly to attribute['key] and attribute['value']['value']. I'm still going to play around with it, but I still would like some advice.

steponafish avatar Jan 25 '19 15:01 steponafish

Fixed it. It was an indent error.

steponafish avatar Jan 25 '19 16:01 steponafish