All pastes #906679 Raw Edit

Untitled

public python v1 · immutable
·published 2008-02-16 21:54 UTC
rendered paste body
from BeautifulSoup import BeautifulSoupfrom urllib2 import urlopenimport reSOURCE = 'http://code.google.com/p/macvim/downloads/list?%s&%s' % (    'can=1',  # show all files    'colspec=Filename+DownloadCount')  # we only need name and download countNAMES_ATTRIBS = {'class' : re.compile(r'col_0$') }COUNTS_ATTRIBS = {'class' : re.compile(r'col_1$') }def fetchNewColumn():  soup = BeautifulSoup(urlopen(SOURCE))  resultstable = soup.find('table', id='resultstable')  names = [str(x.a.string) for x in resultstable.findAll('td', NAMES_ATTRIBS)]  counts = [int(x.a.string) for x in resultstable.findAll('td', COUNTS_ATTRIBS)]  return dict(zip(names, counts))