2

Python を使用して Google クエリのヒット数を取得するにはどうすればよいですか?

ビートルズの曲のタイトルを含むリストがあります。

    songs = ["Love Me Do", "P. S. I Love You", "Please Please Me"]

そして、Google で検索したときに Google のヒット数を取得したいと思います。

    The Beatles Love Me Do
    The Beatles P. S. I Love You
    The Beatles Please Please Me

そして、これらのヒットを別のリストに保存します。したがって、最終的には次のようになります。

    google_hits == [42400000, 2740000, 28200000]
4

2 に答える 2

3

これは私が実装した迅速で汚い解決策です:

import urllib
import json

artist = "The Beatles"
songs = ["Love Me Do", "P. S. I Love You", "Please Please Me"]
query = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%s"

google_hits = list()
for song in songs:
    results = urllib.urlopen(query % (artist + " " + song))
    json_res = json.loads(results.read())
    google_hits.append(int(json_res['responseData']['cursor']['estimatedResultCount']))

print google_hits

私は非推奨のオープンGoogle Search APIを使用していますが、新しいCustom Search APIの API キーを自分で取得すれば、プロセスは同様になります。また、ドキュメントからの簡単なメモ:estimatedResultCount

.estimatedResultCount - 現在のクエリに一致する結果の推定数を提供します。この値は、Google.com の検索プロパティに表示される同様の値と必ずしも一致しないことに注意してください。

于 2012-11-27T23:46:22.740 に答える
0

このコードを書くのに xgoogle が役立つかもしれません: https://github.com/pkrumins/xgoogle

以下は、検索結果を反復処理してカウントする方法を示す実用的なコードです。xgoogle の使用方法

于 2012-11-27T23:24:54.137 に答える