2009-07-22 49 views
1

Jon Skeet有以下由C#構建的reputation tracker建立一個像Jon的Python類似的名譽追蹤器

我感興趣的被Python構建一個類似的應用程序,使得至少以下模塊使用

  • 美麗的湯
  • defaultdict

我們顯然需要

數據存儲你怎麼能建立一個類似的信譽系統作爲喬恩的一個被Python?

+0

您的意思是`http://stackoverflow.com/users/recent/userid?Tab = Reputation&StartDate =&EndDate =`? – SilentGhost 2009-07-22 21:59:06

回答

4

的屏幕抓取很容易,如果我理解正確的SO HTML格式,例如,要得到我的代表(我敢用戶95810):

import urllib 
import BeautifulSoup 
page = urllib.urlopen('http://stackoverflow.com/users/95810') 
soup = BeautifulSoup.BeautifulSoup(page) 
therep = str(soup.find(text='Reputation').parent.previous.previous).strip() 
print int(therep.replace(',','')) 

我不知道你想什麼儘管在這裏用defaultdict來做 - 你希望在這個int上執行什麼進一步的處理,這會以某種方式需要將它存儲在defaultdict中?

+0

謝謝Alex! ---你說得對,我們在這裏不需要`defaultdict`。 – 2009-07-23 08:43:53