Beautiful Soup | next_siblings property
Start your free 7-days trial now!
In Beautiful Soup, the
next_siblings property of a tag or a string returns a generator used to iterate over all the subsequent tags and strings under the same parent.
Consider the following HTML document:
my_html = """<div><p>Alex</p><p>Bob</p></div>"""soup = BeautifulSoup(my_html)
Let's get the
Here, we've used the
repr(~) method to escape the newline character so that you can explicitly see
'\n' instead of an empty line. To break this down, the
<p>Alex</p> is a newline character, which might be surprising for those who expected to see
<p>Bob</p>. Such a result arises because there is a new line character
If you just wanted to access the next sibling elements, then the better alternative would be to call the