2

Py_Stackexchange統計分析のためにデータを取得するために使用してStackoverflowいますが、問題に遭遇しました。

回答に対する賛成票と反対票を取得する必要があります。オブジェクトがstackexchange.Answerあり、次のような文字列のタプルである「transfers」というフィールドがあります。

'is_accepted', 'locked_date', 'question_id', 'up_vote_count', 'down_vote_count',
'view_count', 'score', 'community_owned', 'title', 'body'

これらのフィールドに対応する実際の数値を取得するにはどうすればよいですか?

4

1 に答える 1

2

この回答のために Py-Stackexchange が提供する質問のデモを利用しました。

最も重要なことは、フィルタにup_vote_countおよびdown_vote_count属性が含まれていることを確認することです。

このフィルターを取得したら、値にアクセスできますquestion.up_vote_count(またはanswer.up_vote_count回答を確認している場合)。

例として、デモの 22 行目を変更して、次の 2 つの属性をフィルターに含めました。

question = site.question(id, filter="!b0OfMwwD.s*79x")

フィルタはここで作成できます。

次に、スクリプトの最後に次の行を追加しました。

print('%d Upvotes.' % question.up_vote_count)

この質問に対して実行すると、次の出力が得られます。

Please enter an API key if you have one (Return for none):
Enter a question ID: 26143702
--- Getting the upvotes of an answer using Py-Stackexchange ---
<p>I'm using <code>Py_Stackexchange</code> to pull data from <code>Stackoverflow</code> for some statistical analysis, and stumbled upon a problem.</p>

<p>I need to retrieve the upvotes and downvotes on an answer. I have the <code>stackexchange.Answer</code> object, and it has a field called 'transfers' which is a tuple of strings like:</p>

<pre><code>'is_accepted', 'locked_date', 'question_id', 'up_vote_count', 'down_vote_count',
'view_count', 'score', 'community_owned', 'title', 'body'
</code></pre>

<p>How do I get the actual numerical values corresponding to these fields?</p>


0 answers.
1 Upvotes.
于 2014-10-01T14:43:57.303 に答える