我需要在python中解析一个html文件,并将内容存储在一个列表中。
示例:['', '
', '']下面是我现在对缓冲函数的看法:
def getTexte(fp,compte=0): #returns the text before a html tag
txt=""
pos=fp.tell() #stock the curr position for later use
tmppos=fp.tell() #same here
for car in fp.read():
if car=="
fp.seek(tmppos) #we get back to juste before the html tag
break # and we leave this damn for
txt=txt+car #we concatenate each car in the string
tmppos=fp.tell() #and stock the pos for later use
if compte==0:
fp.seek(pos)
if txt!="":
return txt现在这里是我得到的一个示例输出:
['
', 'Blablabla', 'lablabla', 'ablabla', 'blabla', 'labla', 'abla', 'bla', 'la', 'a', '
']我不明白为什么。也许太累了。