In [2]:
fname='SiF-energy.stmx'
from webutils import Soup

In [3]:
text=Soup(fname)

In [26]:
stocks=text('stock')
for stock in stocks:
    name=stock.get('name')
    if name:
        name=name.replace('\\n','_')
        print name


Coal_Generation_Capacity
Natural_Gas_Generation_Capacity
Nuclear_Generation_Capacity
Renewables_Generation_Capacity
Hydro_Generation_Capacity
Other_Generation_Capacity

In [31]:
stock=stocks[0]
print stock


<stock name="Coal_Generation\nCapacity">
<eqn>3845 {million}</eqn>
<inflow>developing_coal</inflow>
<outflow>converting_to_natural_gas</outflow>
<outflow>retiring_coal</outflow>
<non_negative>
<units>kilowatt hours per day</units>
<display x="261" y="68.6667">
</display></non_negative></stock>

In [32]:
stock.get('name')


Out[32]:
u'Coal_Generation\\nCapacity'

In [38]:
stock('eqn')[0].contents[0]


Out[38]:
u'3845 {million}'

In [ ]: