GET 10% OFF on all Annual Plans. Use Code - FETCH2024

How to select elements by class in XPath?

In XPath, you can select elements by class using the contains() function and the @class attribute. Here is an example:
Example of Extracting title tag using requests and BS4.
//tag[contains(@class,'classname')]
In the above XPath, replace tag with the tag name of the element you want to select (e.g. div, p, a, etc.), and replace classname with the name of the class, you want to select.
For example, if you want to select all div elements that have the class name learn, you can use the following XPath:
//div[contains(@class,'learn')]
This will select all div elements that have the class name learn, regardless of the order of the classes in the class attribute.