Getting nth child element in Beautiful Soup
To get the 2nd child element in Beautiful Soup, for instance, use the
select_one(~) method like so:
select_one(~) method takes in a CSS selector, and this is precisely the syntax we use to fetch the nth child element.
Consider the following HTML document:
my_html = """<div><p>Alex</p><p>Bob</p><p>Cathy</p></div>"""soup = BeautifulSoup(my_html)
To get the second element under the