Retrieve a neighboring tag in CSS (or in PHP with the Goutte library)

100 Views Asked by At

I am currently developing a platform using WebScraping with the Goutte library in PHP and I would have liked to know if it was possible to select in the case of an html table a neighboring "tr" tag in CSS or quite simply with Goutte.

This is what my array looks like and the items I want to retrieve:

My table

My HTML Table code : https://codepen.io/qsavean/pen/OJjNLjz

I managed to retrieve the notes and the names of the tests with the nth-child pseudo-class in CSS from the tr tag comprising the CSS class ".toggle4" but here is the problem is that now I want to retrieve the material for which the test scores are attached to, however these are located in another neighboring tr tag composing the CSS class ".notes_bulletin_row_mod". Concretely, I want to recover the names of the subjects with their notes separately.

Example :

-----------------------------------
Matter :  Algorithmie Avancee <- (I want to retrieve the name of the module)
Test name : DS PAPIER
Note : 10.50 / 20.0
-----------------------------------

-----------------------------------
Matter :  Methodologie de Production logiciels <- (I want to retrieve the name of the module)
Test name : Interro 1
Note : 10 / 20.0
-----------------------------------

Here is what my code looks like currently which retrieves the info from the tr tag comprising the class ".toggle4" (names and notes of the tests) :

    // Take the set of values of tr .toggle4
    $crawler->filter('.toggle4:nth-child(1n+1)')->each(function($node){

    // Get the name of the tests
    $node->filter('td:nth-child(4)')->each(function($node){
        echo $node->text() . PHP_EOL;
    });

    // Get the notes
    $node->filter('td:nth-child(5)')->each(function($node){
        echo $node->text() . PHP_EOL;
    });

The values I want to retrieve are in red : My values

Hoping to have was clear enough.

0

There are 0 best solutions below