python读取部分文件_如何读取文件的一部分(解析),在python中的“

我需要在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', '

']我不明白为什么。也许太累了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值