'How to parse and scrape the content of WordPress

Is it possible to have a custom function to truncate the contents of a defined DIV on a blog post page to use as the summary on the blog index page. So rather than using $the_content or $the_excerpt - Is it possible to create $the_customContent and have some PHP which checks the blog post page and collects the content of the div with class "ThisIsTheContentToUse" - reason for this is that my blog posts have content on the page above the content I want to be included as the blog summary on the blog index page - so either want to tell WP to ignore those blocks of content, or, probably easier - just tell WP where the content to truncate is - e.g. in the "ThisIsTheContentToUse" div... possible?

If so... how? Can't seem to find anything online that defines this custom functionality - surely I can't be the first person to want to do this...?

Would apply_filters make this possible?

https://developer.wordpress.org/reference/hooks/the_content/

So, The blog post is structured as:

<div class="headerArea">
  <h2>The title is here</h2>
  <ul>
</div>
<div class="bullets">
  <li>Bullet 1</li>
  <li>Bullet 2</li>
  <li>Bullet 3</li>
  </ul>
</div>
<div class="ThisIsTheContentToUse">
  <p>The content starts here</p>
</div>

So, currently with the basic get_the_content, the result is:

"The title is here Bullet 1 Bullet 2 Bullet 3 The content starts here"

But what I want is just the content of the "ThisIsTheContentToUse" div.

So it would be:

"The content starts here"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source