0

ここで「ソーシャル Web 2nd E のマイニング」のコードを読んでいて、例 6 がどのように機能しているかを理解しようとしています! の長さを印刷しようとしていて、statuses異なる結果を出力しています。以下に、2 つのコード スニペットとそれぞれの結果を表示します。異なる結果が得られる理由を誰かが説明してくれることを願っています...事前に感謝します.

1st code snippet:
q = '#python' 

count = 100

# See https://dev.twitter.com/docs/api/1.1/get/search/tweets

search_results = twitter_api.search.tweets(q=q,count=count)

statuses = search_results['statuses']


# Iterate through 5 more batches of results by following the cursor

for _ in range(5):
    print "Length of statuses", len(statuses)
    try:
        next_results = search_results['search_metadata']['next_results']
    except KeyError, e: # No more results when next_results doesn't exist
        break

出力は次のとおりです。

Length of statuses 100
Length of statuses 100
Length of statuses 100
Length of statuses 100
Length of statuses 100

これはまさに私が期待しているものです。しかし、これを上記のコードに追加すると:

q = '#python' 

count = 100

# See https://dev.twitter.com/docs/api/1.1/get/search/tweets

search_results = twitter_api.search.tweets(q=q,count=count)

statuses = search_results['statuses']


# Iterate through 5 more batches of results by following the cursor

for _ in range(5):
    print "Length of statuses", len(statuses)
    try:
        next_results = search_results['search_metadata']['next_results']
    except KeyError, e: # No more results when next_results doesn't exist
        break

    # Create a dictionary from next_results, which has the following form:
    # ?max_id=313519052523986943&q=NCAA&include_entities=1
    kwargs = dict([ kv.split('=') for kv in next_results[1:].split("&") ])

    search_results = twitter_api.search.tweets(**kwargs)
    statuses += search_results['statuses']

出力は次のようになります。

Length of statuses 100
Length of statuses 200
Length of statuses 200

私の質問は、for ループが 5 回ループするように設定されているため、2 回目には 5 つではなく 3 つのバッチのみを出力するのはなぜですか?? そして、なぜそれらはそれぞれ100カウントではないのですか?

4

2 に答える 2

0

これがあなたが探しているものだと思います:

https://github.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition/issues/212

LisaCastellano のソリューションを確認してください。

于 2014-09-25T16:30:53.190 に答える
0

「Mining the Social Web」の著者である Matthew A. Russell のおかげで、彼はここで私の質問に答えてくれまし

于 2013-09-03T20:45:23.257 に答える