Help us understand the problem. What is going on with this article?

google custom searchを使う

More than 5 years have passed since last update.

制約

  • 1日100リクエスト
  • 1ページ10件
  • 10ページまでしか取得できない
  • つまり100件しかURLとれない

マニュアルは
https://developers.google.com/custom-search/v1/using_rest

api keyの取得

API Consoleより取得できる

サンプルコード

結果のjsonをファイルとして出力する

googlesearch.py
#! /usr/bin/python
# -*- coding:utf-8 -*-

import urllib
import json
QUERY = ''
API = ''
NUM = 10

url = 'https://www.googleapis.com/customsearch/v1?'
params = {
    'key': API_KEY,
    'q':QUERY,
    'cx':'013036536707430787589:_pqjad5hr1a',
    'alt':'json',
    'lr' :'lang_en',
}
start = 1
f = open('googleresult.json','w')

for i in range(0,NUM):
    params['start'] = start
    req_url = url + urllib.urlencode(params)
    res = urllib.urlopen(req_url)
    dump = json.loads(res.read())
    f.write(json.dumps(dump) + "\n")
    if not dump['queries'].has_key('nextPage'):
        break
    start = int(dump['queries']['nextPage'][0]['startIndex'])

f.close()

ysekky
Gunosy co-founder 推薦エンジンとか作ります
gunosy
情報キュレーションサービス「グノシー」や「ニュースパス」の開発・運営を通じて、情報を世界の人に最適に届けていきます。
http://gunosy.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした