In [1]:
from bs4 import BeautifulSoup, NavigableString, Tag
fname = "resources/outputfiles/V_7_2/5ZoneCAVtoVAVWarmestTempFlowTable_ABUPS.html"
soup = BeautifulSoup(open(fname, 'r'))

In [2]:
btables = soup.find_all(['p', 'table', 'hr'])

In [3]:
atables = soup.hr.find_all(['p', 'table', 'hr'])

In [4]:
for i, t in enumerate(btables):
    if t.name == 'hr':
        for j in t:
#             print j.name
            pass

In [5]:
ctables = soup.hr.find_all()

In [6]:
for child in soup.body:
    print child.name


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-d2a9d01e62cd> in <module>()
      1 for child in soup.body:
----> 2     print child.name

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'

In [7]:
len(soup)


Out[7]:
4

In [8]:
for i in soup:


  File "<ipython-input-8-3856909d8bca>", line 1
    for i in soup:
                  ^
SyntaxError: unexpected EOF while parsing

In [9]:
soup.find_all('p')


Out[9]:
[<p><a href="#toc" style="float: right">Table of Contents</a></p>,
 <p>Program Version:<b>EnergyPlus-Windows-OMP-32 7.2.0.006, YMD=2013.01.28 16:38</b></p>,
 <p>Tabular Output Report in Format: <b>HTML</b></p>,
 <p>Building: <b>Building</b></p>,
 <p>Environment: <b>San Francisco Intl Ap CA USA TMY3 WMO#=724940</b></p>,
 <p>Simulation Timestamp: <b>2013-01-28
  16:38:08</b></p>,
 <p><a href="#toc" style="float: right">Table of Contents</a></p>,
 <p>Report:<b> Annual Building Utility Performance Summary</b></p>,
 <p>For:<b> Entire Facility</b></p>,
 <p>Timestamp: <b>2013-01-28
    16:38:08</b></p>,
 <p><b>Table of Contents</b></p>]

In [10]:
print soup.next


None

In [11]:
p = soup.find_all('p')

In [12]:
p[0].children.next()


Out[12]:
<a href="#toc" style="float: right">Table of Contents</a>

In [13]:
hr = soup.hr.children

In [14]:
hr.next()


Out[14]:
u'\n'

In [15]:
for i in hr:
    print i.name


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-6ec4fc9b09b9> in <module>()
      1 for i in hr:
----> 2     print i.name

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'
p

In [16]:
hr = soup.hr.children

In [17]:
br = soup.hr.br

In [17]:


In [18]:
for i in soup.hr.descendants:
    if i.name not in ( 'tr', 'td', None, 'br'):
        if i.name == 'p':
            print i


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-cdd2bde62ff2> in <module>()
      1 for i in soup.hr.descendants:
----> 2     if i.name not in ( 'tr', 'td', None, 'br'):
      3         if i.name == 'p':
      4             print i

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'

In [19]:
pr = soup.table.next_siblings

In [20]:
for i in pr:
    print i.name


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-9407ae26a156> in <module>()
      1 for i in pr:
----> 2     print i.name

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'

In [21]:
print pr.previous_sibling


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-9735192ee4f6> in <module>()
----> 1 print pr.previous_sibling

AttributeError: 'generator' object has no attribute 'previous_sibling'

In [22]:
pr = soup.table.previous_elements

In [41]:
for i in pr:
    try:
        name = i.name
    except AttributeError, e:
        continue    
    if i.name not in ('br', None):
        if i.name == 'hr':
            break
        print i


<b>Site and Source Energy</b>
<b></b>
<b>Values gathered over      8760.00 hours</b>
<b>2013-01-28
    16:38:08</b>
<p>Timestamp: <b>2013-01-28
    16:38:08</b></p>
<b> Entire Facility</b>
<p>For:<b> Entire Facility</b></p>
<b> Annual Building Utility Performance Summary</b>
<p>Report:<b> Annual Building Utility Performance Summary</b></p>
<a name="AnnualBuildingUtilityPerformanceSummary::EntireFacility"></a>
<a href="#toc" style="float: right">Table of Contents</a>
<p><a href="#toc" style="float: right">Table of Contents</a></p>

In [24]:
tb = soup.find_all('table')

In [25]:
for el in soup.table.next:
    if el.name == 'table':
        print el.name


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-25-e40149827360> in <module>()
      1 for el in soup.table.next:
----> 2     if el.name == 'table':
      3         print el.name

AttributeError: 'unicode' object has no attribute 'name'

In [26]:
d = soup.body.next_element

In [27]:
e = soup.table.next_elements

In [51]:
def has_name(i):
    try:
        name = i.name
        return True
    except AttributeError, e:
        return False    


pr = soup.table.previous_elements
for i in pr:
    if not has_name(i):
        continue
    if i.name not in ('br', None):
        if i.name == 'hr':
            break
        print i.name
e = soup.table.next_elements
for j in e:
    if not has_name(j):
        continue
    if j.name == 'table':
        print j.name
        pr = j.previous_elements
        for i in pr:
            if not has_name(i):
                continue
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                print i.name


b
b
b
b
p
b
p
b
p
a
a
p
table
b
table
b
table
b
table
b
i
table
b
b
table
b
table
b
table
b
table
b
table
b
table

In [52]:
def has_name(i):
    try:
        name = i.name
        return True
    except AttributeError, e:
        return False    

e = soup.p.next_elements
for j in e:
    if not has_name(j):
        continue
    if j.name == 'table':
        print j.name
        pr = j.previous_elements
        for i in pr:
            if not has_name(i):
                continue
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                print i.name


table
b
b
b
b
p
b
p
b
p
a
a
p
table
b
table
b
table
b
table
b
i
table
b
b
table
b
table
b
table
b
table
b
table
b
table

In [54]:
def has_name(i):
    try:
        name = i.name
        return True
    except AttributeError, e:
        return False    

all = []
e = soup.p.next_elements
for j in e:
    tabletup = []
    if not has_name(j):
        continue
    if j.name == 'table':
        print j.name
        beforetable = []
        pr = j.previous_elements
        for i in pr:
            if not has_name(i):
                continue
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                print i.name
                beforetable.append(i.name)
        beforetable.reverse()
        tabletup.append(beforetable)
        tabletup.append(j.name)
    if tabletup:
        all.append(tabletup)


table
b
b
b
b
p
b
p
b
p
a
a
p
table
b
table
b
table
b
table
b
i
table
b
b
table
b
table
b
table
b
table
b
table
b
table

In [56]:
def has_name(i):
    try:
        name = i.name
        return True
    except AttributeError, e:
        return False    

all = []
e = soup.p.next_elements
for j in e:
    tabletup = []
    if not has_name(j):
        continue
    if j.name == 'table':
        print j.name
        beforetable = []
        pr = j.previous_elements
        for i in pr:
            if not has_name(i):
                continue
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                print i.name
                beforetable.append(i)
        beforetable.reverse()
        tabletup.append(beforetable)
        tabletup.append(j)
    if tabletup:
        all.append(tabletup)


table
b
b
b
b
p
b
p
b
p
a
a
p
table
b
table
b
table
b
table
b
i
table
b
b
table
b
table
b
table
b
table
b
table
b
table

In [67]:
for line in all[0][0]:
    if line.name == 'p':
        print line.get_text()


Table of Contents
Report: Annual Building Utility Performance Summary
For: Entire Facility
Timestamp: 2013-01-28
    16:38:08

In [81]:
fname = "resources/outputfiles/V_8_1/1050PageMillRoadTable.html"
soup = BeautifulSoup(open(fname, 'r'))

In [82]:
all = []
e = soup.p.next_elements
for j in e:
    tabletup = []
    if not has_name(j):
        continue
    if j.name == 'table':
        print j.name
        beforetable = []
        pr = j.previous_elements
        for i in pr:
            if not has_name(i):
                continue
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                if i.parent.name == "p":
                    print i.name, "parent", i.parent.name
                else:
                    print i.name
                    beforetable.append(i)
        beforetable.reverse()
        tabletup.append(beforetable)
        tabletup.append(j)
    if tabletup:
        all.append(tabletup)


table
b
b
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
table
b
table
b
i
table
b
b
table
b
table
b
table
b
table
b
table
b
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b
table
b
table
b
table
b
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
i
table
b
i
table
b
table
b
i
table
b
table
b
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
table
b
table
b
table
b
table
b
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
table
b
table
b
table
b
table
b
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
table
b
table
b
table
b
table
b
table
b
table
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
table
b
table
b
table
b
table
b
table
b

In [3]:
def _has_name(soup_obj):
    """checks if soup_obj is really a soup object or just a string
    If it has a name it is a soup object"""
    try:
        name = soup_obj.name
        return True
    except AttributeError, e:
        return False    

linestables = []
e = soup.p.next_elements
for j in e:
    tabletup = []
    if not _has_name(j):
        continue
    if j.name == 'table':
        print j.name
        beforetable = []
        pr = j.previous_elements
        for i in pr:
            if not _has_name(i):
                continue
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                if i.parent.name == "p":
                    print i.name, "parent", i.parent.name
                else:
                    print i.name
                    beforetable.append(i)
        beforetable.reverse()
        tabletup.append(beforetable)
        tabletup.append(j)
    if tabletup:
        linestables.append(tabletup)


table
b
b
b
b parent p
p
b parent p
p
b parent p
p
a
a parent p
p
table
b
table
b
table
b
table
b
i
table
b
b
table
b
table
b
table
b
table
b
table
b
table

In [5]:
for block in linestables:
    for line in block[0]:
        print line.get_text()
    print '- Table -----'


Table of Contents

Report: Annual Building Utility Performance Summary
For: Entire Facility
Timestamp: 2013-01-28
    16:38:08
Values gathered over      8760.00 hours

Site and Source Energy
- Table -----
Site to Source Energy Conversion Factors
- Table -----
Building Area
- Table -----
End Uses
- Table -----
Note: Natural gas appears to be the principal heating source based on energy usage.
End Uses By Subcategory
- Table -----
Normalized Metrics
Utility Use Per Conditioned Floor Area
- Table -----
Utility Use Per Total Floor Area
- Table -----
Electric Loads Satisfied
- Table -----
On-Site Thermal Sources
- Table -----
Water Source Summary
- Table -----
Comfort and Setpoint Not Met Summary
- Table -----
- Table -----

In [106]:
pk = ([(i, line.get_text(), block[-1]) for line in block[0] if 'PEAK' in line.get_text()] for i, block in enumerate(all))
imgs = [str(p[-1]) for p in pk if p]
HTML(imgs[1])


Out[106]:
(79, u'Report: COMPONENTS OF PEAK NET ELECTRICAL DEMAND',
ELECTRICITYNET:FACILITY [J] ELECTRICITYNET:FACILITY {Maximum}[W] ELECTRICITYNET:FACILITY {TIMESTAMP} INTERIORLIGHTS:ELECTRICITY {AT MAX/MIN} [W] INTERIOREQUIPMENT:ELECTRICITY {AT MAX/MIN} [W] FANS:ELECTRICITY {AT MAX/MIN} [W] HEATING:ELECTRICITY {AT MAX/MIN} [W] COOLING:ELECTRICITY {AT MAX/MIN} [W] EXTERIORLIGHTS:ELECTRICITY [Invalid/Undefined] PUMPS:ELECTRICITY {AT MAX/MIN} [W] HEATREJECTION:ELECTRICITY [Invalid/Undefined] EXTERIOREQUIPMENT:ELECTRICITY [Invalid/Undefined] HUMIDIFICATION:ELECTRICITY [Invalid/Undefined] HEATRECOVERY:ELECTRICITY [Invalid/Undefined] WATERSYSTEMS:ELECTRICITY [Invalid/Undefined] REFRIGERATION:ELECTRICITY [Invalid/Undefined] GENERATORS:ELECTRICITY [Invalid/Undefined] ELECTRICITYPRODUCED:FACILITY [Invalid/Undefined]
January 0.171128E+12 157049.426 31-JAN-13:00 71973.843 53980.383 11549.438 0.000 19536.328 0.000 9.434 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
February 0.160835E+12 193039.840 03-FEB-13:00 71973.843 53980.383 12471.156 0.000 54492.992 0.000 121.467 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
March 0.212043E+12 208946.687 10-MAR-14:30 71973.843 53980.383 13828.046 0.000 69138.247 0.000 26.168 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
April 0.181469E+12 201248.208 14-APR-15:00 71973.843 53980.383 13769.302 0.000 61507.074 0.000 17.607 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
May 0.203926E+12 197284.804 11-MAY-15:00 71973.843 53980.383 12941.561 0.000 58373.490 0.000 15.528 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
June 0.232938E+12 213394.890 13-JUN-15:00 71973.843 53980.383 13916.013 0.000 73510.289 0.000 14.363 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
July 0.230901E+12 235258.279 12-JUL-15:15 71973.843 53980.383 14525.904 0.000 94771.056 0.000 7.093 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
August 0.255759E+12 228777.354 30-AUG-14:00 71973.843 53980.383 15823.009 0.000 86987.338 0.000 12.781 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
September 0.245803E+12 246369.600 29-SEP-14:30 71973.843 53980.383 21705.841 0.000 98703.816 0.000 5.717 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
October 0.215025E+12 216010.129 10-OCT-14:00 71973.843 53980.383 18295.672 0.000 71743.938 0.000 16.292 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
November 0.179267E+12 197527.989 07-NOV-13:00 71973.843 53980.383 14517.081 0.000 57006.712 0.000 49.971 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
December 0.172032E+12 191824.399 13-DEC-13:30 71973.843 53980.383 12761.796 0.000 53013.048 0.000 95.330 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
                                     
Annual Sum or Average 0.246113E+13               0.000   0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
Minimum of Months 0.160835E+12 157049.426   71973.843 53980.383 11549.438 0.000 19536.328 0.000 5.717 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
Maximum of Months 0.255759E+12 246369.600   71973.843 53980.383 21705.841 0.000 98703.816 0.000 121.467 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
)

In [104]:



Out[104]:
2

In [69]:
pr = soup.table.previous_elements
for i in pr:
    if i.name not in ('br', None):
        if i.name == 'hr':
            break
        print i.get_text()
e = soup.table.next_elements
for j in e:
    if j.name == 'table':
        print j.name
        pr = j.previous_elements
        for i in pr:
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                print i.get_text()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-69-aa34f52be7f0> in <module>()
      1 pr = soup.table.previous_elements
      2 for i in pr:
----> 3     if i.name not in ('br', None):
      4         if i.name == 'hr':
      5             break

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'

In [30]:
pr = soup.table.previous_elements
for i in pr:
    if i.name not in ('br', None):
        if i.name == 'hr':
            break
        if i.name == 'p':
            print i.get_text()
e = soup.table.next_elements
for j in e:
    if j.name == 'table':
        print j.name
        pr = j.previous_elements
        for i in pr:
            if i.name not in ('br', None):
                if i.name in ('table', 'hr', 'tr', 'td'):
                    break
                print i.get_text()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-30-faac7f6a7b01> in <module>()
      1 pr = soup.table.previous_elements
      2 for i in pr:
----> 3     if i.name not in ('br', None):
      4         if i.name == 'hr':
      5             break

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'

In [31]:
soup.table.previousSibling?

In [32]:
from IPython.display import HTML

In [33]:
print str(soup.table)


<table border="1" cellpadding="4" cellspacing="0">
<tr><td></td>
<td align="right">Total Energy [kWh]</td>
<td align="right">Energy Per Total Building Area [kWh/m2]</td>
<td align="right">Energy Per Conditioned Building Area [kWh/m2]</td>
</tr>
<tr>
<td align="right">Total Site Energy</td>
<td align="right">    47694.47</td>
<td align="right">       51.44</td>
<td align="right">       51.44</td>
</tr>
<tr>
<td align="right">Net Site Energy</td>
<td align="right">    47694.47</td>
<td align="right">       51.44</td>
<td align="right">       51.44</td>
</tr>
<tr>
<td align="right">Total Source Energy</td>
<td align="right">   140159.10</td>
<td align="right">      151.16</td>
<td align="right">      151.16</td>
</tr>
<tr>
<td align="right">Net Source Energy</td>
<td align="right">   140159.10</td>
<td align="right">      151.16</td>
<td align="right">      151.16</td>
</tr>
</table>

In [34]:
HTML(str(soup.table))


Out[34]:
Total Energy [kWh] Energy Per Total Building Area [kWh/m2] Energy Per Conditioned Building Area [kWh/m2]
Total Site Energy 47694.47 51.44 51.44
Net Site Energy 47694.47 51.44 51.44
Total Source Energy 140159.10 151.16 151.16
Net Source Energy 140159.10 151.16 151.16

In [35]:
for t in soup.table.next_elements:
    if t.name == 'table':
        HTML(str(t))
        break


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-35-ec63312f6647> in <module>()
      1 for t in soup.table.next_elements:
----> 2     if t.name == 'table':
      3         HTML(str(t))
      4         break

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'

In [36]:
HTML(str(t))


Out[36]:

In [37]:
ts = soup.table.next_elements

In [38]:
l = [str(i) for i in ts if i.name == 'table']


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-38-c033ef8b668c> in <module>()
----> 1 l = [str(i) for i in ts if i.name == 'table']

/Users/santosh/.virtualenvs/eplus/lib/python2.7/site-packages/bs4/element.pyc in __getattr__(self, attr)
    665             raise AttributeError(
    666                 "'%s' object has no attribute '%s'" % (
--> 667                     self.__class__.__name__, attr))
    668 
    669     def output_ready(self, formatter="minimal"):

AttributeError: 'NavigableString' object has no attribute 'name'

In [39]:
HTML(l[-1])


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-39-c31a7a062543> in <module>()
----> 1 HTML(l[-1])

NameError: name 'l' is not defined

In [ ]: