html - Use the Google Custom Search API to search the web from Python -


i'm newbee in python, html , css , trying reverse engineer "https://github.com/scraperwiki/google-search-python" learn 3 , use google custom search api search web python. specifically, want search search engine made through google custom search "https://cse.google.com/cse/publicurl?cx=000839040200690289140:u2lurwk5tko"i looked through code made minor adjustments , came following. "search.py"

import os google_search import googlecustomsearch #this traceback import traceback import sys  #set variables os.environ["search_engine_id"] = "000839...   " os.environ["google_cloud_api_key"] = "aiza...   "  search_engine_id = os.environ['search_engine_id']                            api_key = os.environ['google_cloud_api_key']  api = googlecustomsearch(search_engine_id, api_key)  print("we got here\n")  #for result in api.search('prayer', 'https://cse.google.com/cse/publicurl?cx=000839040200690289140:u2lurwk5tko'): result in api.search('pdf', 'http://scraperwiki.com'):     print(result['title'])      print(result['link'])      print(result['snippet'])   print traceback.format_exc() 

and import ("at least relevant parts") believe comes following code in google_search.py

class googlecustomsearch(object):     def __init__(self, search_engine_id, api_key):         self.search_engine_id = search_engine_id         self.api_key = api_key      def search(self, keyword, site=none, max_results=100):         assert isinstance(keyword, basestring)          start_index in range(1, max_results, 10):  # 10 max page size             url = self._make_url(start_index, keyword, site)             logging.info(url)              response = requests.get(url)             if response.status_code == 403:                 log.info(response.content)             response.raise_for_status()             search_result in _decode_response(response.content):                 yield search_result                 if 'nextpage' not in search_result['meta']['queries']:                     print("no more pages...")                     return 

however, when try compile it, following.

enter image description here

so, here's problem. cant quite figure out why following lines of code don't print terminal. overlooking?

print(result['title'])  print(result['link'])  print(result['snippet'])  

the thing can think of didn't take correct id or something. created google custom search , project on google developers console quick start suggested. here got search_engine_id , google_cloud_api_key from.

enter image description here enter image description here

after added stacktrace suggested in comments got this

enter image description here

am misunderstanding code, or there else i'm missing? appreciate clues me solve problem, i'm kind of stumped right now.

thanks in advance guys!


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -