Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Working with Specific Elements
course content

Course Content

Web Scraping with Python

Working with Specific ElementsWorking with Specific Elements

Navigating an HTML document using Python attributes will retrieve only the first occurrence of a particular element. But what if you're interested in the first instance of an element and don't know its full path? In such cases, you can utilize the .find() method, passing the tag (without < > brackets) as a string. For example, let's locate the first <div> element in the HTML document.

Furthermore, you can retrieve all instances of a specific element by employing the .find_all() method. This will yield a list of instances. For instance, let's locate all the <p> tags in the HTML document.

You can also use the .find_all() method to find not just one but multiple tags by providing a list of tags. For example, let's gather all the <div> and <title> elements.

Everything was clear?

Section 2. Chapter 5
some-alt