2014-10-01 77 views
2

我正在使用Py_StackexchangeStackoverflow中抽取數據進行一些統計分析,並偶然發現問題。使用Py-Stackexchange獲取答案的答案

我需要在答案中檢索upvotes和downvotes。我有stackexchange.Answer對象,而且它有一個名爲「轉移」字段這就好比字符串的元組:

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

我如何獲得對應於這些領域的實際數值?

+0

您使用的庫過程這個或原始的API響應......因爲它在'up_vote_count'和'down_vote_count' - 如果你有這麼遠 - 不太清楚你想要解決什麼問題? – 2014-10-01 14:32:34

回答

1

我利用Py-Stackexchange提供的question演示來解答這個問題。

您需要做的最重要的事情是確保您的過濾器包含up_vote_countdown_vote_count屬性。

擁有此篩選器後,您可以通過question.up_vote_count(或answer.up_vote_count,如果您正在檢查答案)訪問該值。

作爲一個例子,我修改線22在演示中,包括在過濾器這兩個屬性:

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

過濾器here

然後我在腳本的最後添加這一行:

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.