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_countdown_vote_count属性。

拥有此过滤器后,您可以通过question.up_vote_count(或者answer.up_vote_count如果您正在检查答案)访问该值。

例如,我修改了演示中的第 22 行,将这两个属性包含在过滤器中:

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 回答