galaxyan
galaxyan

Reputation: 6111

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

Upvotes: 5

Views: 2690

Answers (5)

Ari Seyhun
Ari Seyhun

Reputation: 12521

I just want to point out, if you try opening your public custom google search in a new incognito window, you might see more similar results as your API. For me, Google seems to be showing different results based on my Google account, and incognito showed no results for my search.

Upvotes: 0

galaxyan
galaxyan

Reputation: 6111

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.

Upvotes: 3

 van9petryk
van9petryk

Reputation: 141

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

Upvotes: 0

Naguib Ihab
Naguib Ihab

Reputation: 4496

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

Upvotes: 0

Jeffrey Ng
Jeffrey Ng

Reputation: 67

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.

Upvotes: 0

Related Questions