我编写了一些代码来解析HTML页面,使用beautiful soup得到一个树状结构。树状结构是使用名为Item的数据类型及其子属性.child()实现的。生成的树状结构重复了孩子们好几次,所以我不确定问题到底出在哪里
def Parse(self,i):
if(not None):
child=[]
content=""
if(i.contents is not None):
for k in i.contents:
#print(k)
if(type(k)==bs4.element.NavigableString):
content+=k
elif(type(k)==bs4.element.Tag):
print(k.siblings)
child.append(self.Parse(k))
h=Item(i.name,content=content, attributes=i.attrs)
for t in child:
h.add(t)
return h
目前没有回答
相关问题 更多 >
编程相关推荐