Quick reference

The following commands will help you to navigate down the tree:

  • tag.name: This navigates to the child using the name
  • tag.contents: This lists the children
  • tag.children: This is a generator for children
  • tag.descendants: This is a generator for descendants
  • tag.string: This navigates to a string using .string
  • tag.strings: This is a generator for strings

The following commands will help you to navigate up the tree:

  • tag.parent: This navigates to the parent
  • tag.parents: This is a generator for parents

The following commands will help you to navigate sideways:

  • tag.next_sibling: This navigates to the next sibling
  • tag.next_siblings: This is a generator for next siblings
  • tag.previous_sibling: This navigates to the previous sibling
  • tag.previous_siblings ...

Get Getting Started with Beautiful Soup now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.