This one scrapes the information from UMN Lookup

Try it out for yourself at utilitymill.

import BeautifulSoup
import urllib

def html2text(node):
    if not hasattr(node, 'contents'):
        return node.replace('n', ' ')
    if node.isSelfClosing:
        return ' '
    return ''.join([html2text(x) for x in node.contents])

def lookup(username):
    html = urllib.urlopen("http://umn.edu/lookup?UID=" + username).read()
    soup = BeautifulSoup.BeautifulSoup(html)
    data = {}
    for heading in soup('th'):
        key = heading.contents[0][:-1]
        val = html2text(heading.findNext())
        data[key] = val
    return data
Advertisements