All pastes #550768 Raw Edit

Habrahabr

public python v1 · immutable
#550768 ·published 2007-06-08 15:05 UTC
rendered paste body
#!/usr/bin/python#encoding: utf8import re, sys, urllib, timedef fetch_page(num):    sock = urllib.urlopen('http://www.habrahabr.ru/people/page%d/' % num)    html = sock.read().decode('CP1251')    sock.close()    return htmldef grep_users(page):    p = re.compile(u'.*<!--- / &#1042;&#1067;&#1042;&#1054;&#1044; &#1055;&#1054;&#1051;&#1068;&#1047;&#1054;&#1042;&#1040;&#1058;&#1045;&#1051;&#1045;&#1049; --->.*<!--- &#1042;&#1067;&#1042;&#1054;&#1044; &#1055;&#1054;&#1051;&#1068;&#1047;&#1054;&#1042;&#1040;&#1058;&#1045;&#1051;&#1045;&#1049; --->(.*)<!--- / &#1042;&#1067;&#1042;&#1054;&#1044; &#1055;&#1054;&#1051;&#1068;&#1047;&#1054;&#1042;&#1040;&#1058;&#1045;&#1051;&#1045;&#1049; --->.*<!--- / &#1042;&#1067;&#1042;&#1054;&#1044; &#1055;&#1054;&#1051;&#1068;&#1047;&#1054;&#1042;&#1040;&#1058;&#1045;&#1051;&#1045;&#1049; --->.*', re.DOTALL | re.UNICODE);    m = p.match(page)    if m:        ucode = m.group(1)    else:        return []    u = re.compile('.*<td width="10%" align="center">(.*)</td>.*', re.UNICODE)    return u.findall(ucode)users = []for i in range(1, 117):    users = grep_users(fetch_page(i)) + users;    sys.stderr.write('Page %d processed; Total users found: %d\n' % (i, len(users)))    time.sleep(5)c = 0output = u''for u in users:    c = c + 1    output = output + u    if c > 21:        output = output + '<br/>'        c = 0