Select elements ignoring specific items SIMPLE HTML DOM

Asked

Viewed 74 times

-1

I am parsing a table. But within this table there is another table and it is difficult to find the whole elements. I’ll paste the code to illustrate it better.

<table>
  <tr>
     <td>
        Dados Gerais
     </td>
  </tr>
  <tr>
     <td>
        <div>Dados de Nomes</div>
     </td>
     <td>
        <table>
           <tr>
              <td>
                 Nome
              </td>
           </tr>
           <tr>
              <td>
                 João da Silva
              </td>
           </tr>
           <tr>
              <td>
                 Maria da Silva
              </td>
           </tr>
        </table>
     </td>
  </tr>
  <tr>
     <td>
        <div>Dados de Técnicos</div>
     </td>
     <td>
        <table>
           <tr>
              <td>
                 Data
              </td>
           </tr>
           <tr>
              <td>
                 10/09/2019
              </td>
           </tr>
           <tr>
              <td>
                 11/09/2019
              </td>
           </tr>
        </table>
     </td>
  </tr>

I do the find dos tr it returns all tr

$trs = $tabela->find('tr');

But I would like him to ignore the three that are within the table that is within the table.

---------- Edited question ----------

Well, I did a foreach to count how many trs were inside the table and found the exact amount of trs. Example below.

$contar = $tabela->find('tr');
$c=0;
foreach ($contar as $k) {
    $c++;
}
$trCorreto = $trs[$c];
  • Not because I don’t want the first tr, I want the third tr where you have the "Technical Data"

  • I posted the solution I got

  • Wow, but then you’re doing something completely different from what you asked and commented on. Re-read your question and see that the solution you put -- which is wrong, because the question field is only for "the question"-, is totally alien to the solution you put.

  • It’s no different! I just used a parallel solution. I wanted him to ignore the TR inside the second TR. What I did was count the TR inside the second TR to skip them when I loop. Which is the same. I understand that this is not the best solution or the official solution, but it solved the problem.

1 answer

0

Well, your question is not very clear but from what I understand you don’t want to select the elements tr of the nested tables.

So to get only the elements tr which are children, you can use the Jquery function called Children.

$('#tabela').children('tr');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.