Searching, traversing, and iterating

Beautiful Soup provides a lot of methods and properties to traverse and search elements in the parsed tree. These methods are often named in a similar way to their implementation, describing the task they perform. There are also a number of properties and methods that can be linked together and used to obtain a similar result.

The find() function returns the first child that is matched for the searched criteria or parsed element. It's pretty useful in scraping context for finding elements and extracting details, but only for the single result. Additional parameters can also be passed to the find() function to identify the exact element, as listed:

  • attrs: A dictionary with a key-value pair
  • text: With ...

Get Hands-On Web Scraping with Python 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.