Search code examples
phpsymfonygoutte

Filtering with Goutte in Symfony 2+


I am trying to extract a specific value from a html file using goutte

    $client = new Client();
    $crawler = $client->request('GET', 'http://localhost:8081/app_dev.php');
    $htmlContent= $crawler->filter('label')->last()->html();
    var_dump($htmlContent);die();

in this case, I get the snippet:

<input type="password" maxlength="40"  myfield1="KqewkKAFyk7Vmsy" >

I want to extract the value of myfield1 a. how do I achieve that?

I tried allready without any success (result is NULL):

    $htmlContent= $crawler->filter('label')->last()->attr('myfield1');

Solution

  • Your code tries to filter by label instead of input.

    This should work (assuming it's the last input):

    $htmlContent = $crawler->filter('input')->last()->attr('myfield1');