在执行popen函数读取数据后,topData = os.popen('top -n 1')
对数据进行如下处理即可避免:
data= topData.read().replace("\x1b(B\x1b[m", " ").replace("\x1b(B\x1b[m\x1b[39;49m\x1b[K", " ").replace( "\x1b[?1h\x1b=\x1b[?25l\x1b[H\x1b[2J", " ").replace("\x1b[39;49m\x1b[1m", " ").replace("\x1b[39;49m\x1b[K", " ").replace("\x1b[39;49m"," ").replace("\x1b[K", " ").replace("\x1b[7m", " ").replace("\x1b[?1l\x1b>\x1b[45;1H", " ").replace("\x1b[?12l\x1b[?25h"," ").replace("\x1b[1m", " ").replace(' ',' ').replace('\n', '<br/>')
data.close()