M
M
Mark2020-04-26 12:30:47
PHP
Mark, 2020-04-26 12:30:47

How to select element if ids are not unique?

Good afternoon!
I'm trying to parse the page, but I've run into a problem where multiple elements have the same id.
Here is the structure I am trying to parse:

<div class="tabs_p">
 <div class="tabs_p_d">
  <div class="tabs_p_t">Name</div>
  <div class="tabs_p_d"></div>
 </div>
<div class="tabs_p_v">
    5016                        </div>
  </div>
<div class="tabs_p_d">
  <div class="tabs_p_t">ID</div>
  <div class="tabs_p_d"></div>
 </div>
<div class="tabs_p_v">
    506                        </div>
  </div>
<div class="tabs_p_d">
  <div class="tabs_p_t">LS</div>
  <div class="tabs_p_d"></div>
 </div>
<div class="tabs_p_v">
    485                        </div>
  </div>
<div class="tabs_p_d">
  <div class="tabs_p_t">Value</div>
  <div class="tabs_p_d"></div>
 </div>
<div class="tabs_p_v">
    100                        </div>
  </div>

As you can see, the elements don't have unique IDs to select from. But I, for example, need to select a value in the "value" block. How can I get this number 100?
How does the code that parses this page work, for example to get the title:
function Parse($p1, $p2, $p3) {
 $num1 = strpos($p1, $p2);
 if ($num1 === false) return 0;
  $num2 = substr($p1, $num1);
  return strip_tags(substr($num2, 0, strpos($num2, $p3)));
                      }
$string = file_get_contents('$source');
$name = strip_tags(trim(Parse($string, '<h1 item="name">', '</h1>')));

Help, please, can there be some method of selecting not by identifiers, but by the content of the elements?
Or, alternatively, select the last element, because the one I need is always at the end.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question