I am trying to do a Breath First Search on a Beautiful soup tree. I know, we can do a Depth First Search with Beautiful soup like this :
html = """SOME HTML FILE"""
soup = BeautifulSoup(html)
for child in soup.recursiveChildGenerator():
# do some stuff here
pass
But I have no idea how to do a Breath First Search, anyone having any idea, suggestion ?
Thanks for your help.
Use the
.childrengenerator for each element to append to your breadth-first queue: