Я должен преобразовать код BeautifulSoup.По сути, я хочу получить все дочерние элементы узла body, выбрать текст, который им нужен, и сохранить его.Вот код с bs4:
def get_children(self, tag, dorecursive=False):
children = []
if not tag :
return children
for t in tag.findChildren(recursive=dorecursive):
if t.name in self.text_containers \
and len(t.text) > self.min_text_length \
and self.is_valid_tag(t):
children.append(t)
return children
это прекрасно работает, когда я пробую это с lxml lib, потомки пустые:
def get_children(self, tag, dorecursive=False):
children = []
if not tag :
return children
tags = tag.getchildren()
for t in tags:
#print(t.tag)
if t.tag in self.text_containers \
and len(t.tail) > self.min_text_length \
and self.is_valid_tag(t):
children.append(t)
return children
любая идея?