import urllib2 import urllib import json url = "http://ajax/googleapis.com/ajax/services/search/web?v=1.0&" query = raw_input ("What do you want to search for ? >> ") query = urllib.urlencode({'q': query}) response = urllib2.urlopen (url + query).read() data = json.loads (response) results = data ['responseData'] ['results'] for result in results: title = result['title'] url = result['url'] print (title + ';' + url)
ERROR /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 / Users / dragonleo / PycharmProjects / untitled2 / googleapi 您想要寻找什么 ? >>苹果 Traceback(最近一次调用最后一次): 文件“/ Users / dragonleo / PycharmProjects / untitled2 / googleapi”,第8行,in response = urllib2.urlopen(url + query).read() 文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py”,第126行,在urlopen中 return _opener.open(url,data,timeout) 文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py”,第391行,打开 response = self._open(req,data) 文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py”,第409行,在_open中 '_open',req) 在_call_chain中输入文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py”,第369行 result = func(* args) 在http_open中输入文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py”,第1181行 return self.do_open(httplib.HTTPConnection,req) 在do_open中输入文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py”,第1156行 提出URLError(错误) urllib2.URLError:
感谢专家能解释我收到错误的原因
答案 0 :(得分:1)
立即突出两个问题: