access to google with python
Question: how i can access to google !!

i had try that code

    
    
    urllib.urlopen('http://www.google.com')
    

but it's show message `prove you are human` or some think like dat

some people say try user agent !! i dunno !


Answer: You should use the [Google API](http://code.google.com/apis/ajaxsearch/) for
accessing the search. [Here's an example for
python](http://dcortesi.com/2008/05/28/google-ajax-search-api-example-python-
code/). Unutbu provided a link to an [older SO
answer](http://stackoverflow.com/questions/1657570/google-search-from-a-
python-app/1657597#1657597) which contains a corrected version of the same
example code.

    
    
    #!/usr/bin/python
    import urllib, urllib2
    import json
    
    api_key, userip = None, None
    query = {'q' : 'search google python api'}
    referrer = "http://stackoverflow.com/q/3900610"
    
    if userip:
        query.update(userip=userip)
    if api_key:
        query.update(key=api_key)
    
    url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % (
        urllib.urlencode(query))
    
    request = urllib2.Request(url, headers=dict(Referer=referrer))
    json = json.load(urllib2.urlopen(request))
    
    results = json['responseData']['results']
    for r in results:
      print r['title'] + ": " + r['url']
    

