python抓取google搜索url

import sys
url = ('https://ajax.googleapis.com/ajax/services/search/web''?v=1.0&q=%s&rsz=8&start=%s') % (search,page)
try:
    request = urllib2.Request(
    url, None, {'Referer': 'http://www.baidu.com'})
    response = urllib2.urlopen(request)
            
# Process the JSON string.
    results = simplejson.load(response)
    info = results['responseData']['results']
except Exception,e:
    print e
    time.sleep(5)
    continue
            
    for minfo in info:
        for key in minfo.keys():
            if key == 'url':
                 try:
                     print 'url:%s' % minfo[key]

你可能感兴趣的:(python)