この回答のために 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.