Question

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
Was it helpful?

Solution

There is a 'search outside of google'checkbox in the dashboard. you will get the same result after you check it. it takes me a while to find it out. the default sitting is only return search result inside of all google websites.

OTHER TIPS

After some searches, the answer is "It is impossible to have the same result as google.com".

Google clearly stated it: https://support.google.com/customsearch/answer/141877?hl=en

Hope that this is the definite answer.

Just to add to galaxyan answer, you can still do that by changing Sites to search from Search only included sites to Search the entire web

enter image description here

I think you need to experiment with four parameters cr, gl, hl, lr

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top