How to parse dynamic CSS classes when web scraping?

You can parse dynamic CSS classes using text-based XPath matching. Here is a short example of what HTML with dynamic CSS classes might look like:

<div class="dd">
    <h1 class="aa">Product Details</h1>
    <div class="ffa">
        <div class="la">Remaining Stock</div>
        <div class="ad">5</div>
    </div>
</div>

If you want to extract the value of the remaining stock you can target the HTML div tag that contains "Remaining Stock" and then select the sibling div that contains the stock count. You can do so using text-based XPath matching like this:

//div[text()="Remaining Stock"]/following-sibling::div[1]

Note: Indexing starts from 1 in Selenium hence the reason why you use div[1]

Related Data Parsing web scraping questions: