Hw to get div value based on assertText of another div

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

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

This code repeats more than 10k.

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