def to_str_with_format( self ): s = '' cur_p = None # 如果当前文本处于p标签中,记录p i = 0 for tb in self.ns_li: p = self.p_parent(tb) # 一个新段落 if p: if p != cur_p: cur_p = p s += str(p) # 已包含在上个p中,不做处理 else: # 没有在p中,直接加 # 图片居中 if not isinstance(tb,NavigableString) and tb.name == 'img': s += ("<center>"+str(tb)+"</center>") else: s += str( tb ) return html_char_transform(s)
def to_str_with_format(self): s = '' cur_p = None # 如果当前文本处于p标签中,记录p i = 0 for tb in self.ns_li: p = self.p_parent(tb) # 一个新段落 if p: if p != cur_p: cur_p = p s += str(p) # 已包含在上个p中,不做处理 else: # 没有在p中,直接加 # 图片居中 if not isinstance(tb, NavigableString) and tb.name == 'img': s += ("<center>" + str(tb) + "</center>") else: s += str(tb) return html_char_transform(s)
def to_str( self ): s = ''.join( [str(tb).decode('utf8') for tb in self.ns_li if tb ] ) return html_char_transform(s)
def to_str(self): s = ''.join([str(tb).decode('utf8') for tb in self.ns_li if tb]) return html_char_transform(s)