{{{#!python import urllib2 from BeautifulSoup import BeautifulSoup class Element: "A simple container of arbitrary named attributes." def __init__(self, **kw): self.__dict__.update(kw) def __repr__(self): return str(self.__dict__) def FetchElements(): """Chemical Elements Retrieves a list of the basic chemical elements, along with a few of their associated properties. """ opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] page = opener.open("http://en.wikipedia.org/wiki/List_of_elements_by_atomic_number") soup = BeautifulSoup(page) page.close() elements = {} for element in soup.html.body.table.findAll('tr')[1:]: fields = element.findAll('td') number = int(fields[0].renderContents()) name = fields[1].a.renderContents() symbol = fields[2].renderContents() series = fields[4].a.renderContents() elements[number] = Element( number=number, name=name, symbol=symbol, series=series) return elements elements = FetchElements() print elements }}} '''Note(s):''' This example uses standard Python except for [[http://www.crummy.com/software/BeautifulSoup/|the BeautifulSoup package]] which must be installed separately. ---- CategoryPythonInEducation