当前位置: 主页 > 日志 > Webscraping >

[转]Google AJAX Search API Example Python Code

原文地址:http://dcortesi.com/2008/05/28/google-ajax-search-api-example-python-code/


For whatever reason, there aren’t many examples on the net of Python code that can be used

with the Google AJAX Search API. I’m not really sure why this is and perhaps I’m missing something,

but for future reference here’s some sample python code.

 

#!/usr/bin/python

import urllib

import simplejson

query = urllib.urlencode({'q' : 'damon cortesi'})

url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' \

  % (query)

search_results = urllib.urlopen(url)

json = simplejson.loads(search_results.read())

results = json['responseData']['results']

for i in results:

  print i['title'] + ": " + i['url']

 

Google Web Search API的文档:http://code.google.com/intl/zh-CN/apis/websearch/docs/reference.html#_intro_fonje

[日志信息]

该日志于 2011-05-18 17:17 由 redice 发表在 redice's Blog ,你除了可以发表评论外,还可以转载 “[转]Google AJAX Search API Example Python Code” 日志到你的网站或博客,但是请保留源地址及作者信息,谢谢!!    (尊重他人劳动,你我共同努力)
   
验证(必填):   点击我更换验证码

redice's Blog  is powered by DedeCms |  Theme by Monkeii.Lee |  网站地图 |  本服务器由西安鲲之鹏网络信息技术有限公司友情提供

返回顶部