0

大家好,我们正在使用谷歌 api 例如这个 ' http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s ' % 通过 python 脚本查询,但很快它就被阻止了。有什么解决方法吗?谢谢你。

以下是我当前的代码。

#!/usr/bin/env python

import math,sys
import json
import urllib

def gsearch(searchfor):
  query = urllib.urlencode({'q': searchfor})
  url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
  search_response = urllib.urlopen(url)
  search_results = search_response.read()
  results = json.loads(search_results)
  data = results['responseData']
  return data

args = sys.argv[1:]
m = 45000000000
if len(args) != 2:
        print "need two words as arguments"
        exit
n0 = int(gsearch(args[0])['cursor']['estimatedResultCount'])
n1 = int(gsearch(args[1])['cursor']['estimatedResultCount'])
n2 = int(gsearch(args[0]+" "+args[1])['cursor']['estimatedResultCount'])
4

2 回答 2

1

该链接不起作用,并且这里没有代码,所以我只能建议从 API 中找出限制是什么,并适当地延迟您的请求。或者,您可以支付较少限制的 API 使用费用。

于 2013-10-08T15:39:31.713 回答
1
  1. 链接不好。
  2. 通常你可以通过付费使用来克服这个问题。
于 2013-10-08T15:35:51.710 回答