title: Python search with Google's Customsearch API
body: <p>I'm trying to configure in a good way my search script using Google's Search API. </p>
  
  <p>I have some keywords in my input file from whom I'd like to get first 10 results. When I'm searching them manually - the results are extremely different (expected). </p>
  
  <p>Doing it with API - I'm getting really strange output.
  Did anyone have similar problem before ? </p>
  
  <p>Maybe anyone would give me some tips how to configure search engine ? </p>
  
  <p>I've set: <code>*.google.com/*</code></p>
  
  <p>Python script:</p>
  
  <pre><code>#! /usr/bin/env python
  # -*- coding: utf-8 -*-
  
  from googleapiclient.discovery import build
  
  def main():
      service = build('customsearch', 'v1', developerKey="key")
  
      file = open("./data.csv", "r")
      keys = []
  
      for key in file.readlines():
          keys.append(key)
      keys.sort()
  
      for keyword in keys:
          print(u"\nRESULTS SEARCH FOR: %s" % str(keyword))
  
          res = service.cse().list(
              q=keyword,
              cx='cx',
              num=10,
              safe= 'off',
          ).execute()
  
          if not 'items' in res:
              print (u"No result !!\nres is: %s" % str(res))
          else:
              with open("results_data.txt", "w") as f:
                  for item in res['items']:
                      print('\n%s:\n\t%s' % (item['title'], item['link']))
  
  if __name__ == '__main__':
      main()
  </code></pre>