googleの検索結果数を取得


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #googleの検索結果数を見る
  2. def countWord(word):
  3. q = {#'q':'\"'+question+'\"',
  4. 'q':word.encode('utf-8'),
  5. 'v' : 1.0,
  6. 'hl' : 'ja',
  7. 'rsz': 'small'
  8. }
  9. url=u'http://ajax.googleapis.com/ajax/services/search/web?'+ urllib.urlencode(q)
  10. json_result=urlfetch.fetch(url).content
  11. json_result = string.replace(json_result, 'null', '"null"')
  12. try:
  13. dict_result=eval('dict('+json_result+')')
  14. return dict_result['responseData']['cursor']['estimatedResultCount']
  15. except:
  16. return 0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.