Hw to get div value based on assertText of another div

Can we get the value of the upper Div if text/URL match?

<div class="a">
<div class="a_data">
  <div class="p">First Name</div>
  <div class="q">Last Name</div>
  <div class="r">Company Name</div>

This code repeats more than 10k.

I am trying to get 1 if Company Name match.
Any help will be appreciated.