pythongoogle-custom-search

google custom search api return is different from google.com


I am using google api via python and it works, but the result I got from api is totally different from google.com. I found the top result given by custom search are google calendar,google earth and patents. I wonder if there is a way to get same result from custom search api. Thank you

def googleAPICall(self,userInput):  
        try:  
            userInput = urllib.quote(userInput)        
            for i in range(0,1):
                index = i*10+1 
                url = ('https://www.googleapis.com/customsearch/v1?'    
                       'key=%s'
                       '&cx=%s'
                       '&alt=json'
                       '&num=10'
                       '&start=%d'
                       '&q=%s')%(self.KEY,self.CX,index,userInput)   
                print (url)

                request = urllib2.Request(url)
                response = urllib2.urlopen(request)
            returnResults = simplejson.load(response)
            webs = returnResults['items'] 

            for web in webs:
                self.result.append(web["link"])
    except:
        print ("search error")
        self.result.append("http://en.wikipedia.org/wiki/Climate_change")

    return self.result

Solution

  • There is a "search outside of google" checkbox in the dashboard which will give the same result after you check it. It took me a while to find it out that the default settings only return search results for all Google websites.