Changeset 159 for table_parser


Ignore:
Timestamp:
21/11/10 03:21:26 (18 months ago)
Author:
nigel.sim
Message:

Added image support.\ndont save blank text

File:
1 edited

Legend:

Unmodified
Added
Removed
  • table_parser/table_parser.py

    r158 r159  
    5555        return '{"href": "%s", "text": "%s"}'%(self.href, self.text) 
    5656 
     57class Image(object): 
     58    def __init__(self, src): 
     59        self.src = src 
     60    def __repr__(self): 
     61        return '{"src": "%s"}'%(self.src) 
     62 
    5763# Get the item on the top of a stack 
    5864def top(x): 
     
    103109        elif lower(tag) == 'a' and self.anchors and isinstance(top(self._stack), Cell): 
    104110            # add the text we already have 
    105             top(self._stack).append(self._buf) 
     111            if len(self._buf) > 0: 
     112                top(self._stack).append(self._buf) 
    106113            self._buf = '' 
    107114            self._stack.append(Anchor(attrs['href'])) 
     115        elif lower(tag) == 'img' and self.anchors and isinstance(top(self._stack), Cell): 
     116            # add the text we already have 
     117            if len(self._buf) > 0: 
     118                top(self._stack).append(self._buf) 
     119            self._buf = '' 
     120            top(self._stack).append(Image(attrs['src'])) 
    108121 
    109122        #print "Encountered the beginning of a %s tag" % tag 
     
    130143            t = top(self._stack) 
    131144            if isinstance(t, Row): 
    132                 c.append(self._buf) 
     145                if len(self._buf) > 0: 
     146                    c.append(self._buf) 
    133147                t.append(c) 
    134148            else: 
Note: See TracChangeset for help on using the changeset viewer.