Monday, May 22, 2017

How to get single value from Crawler filter()?

Using: https://github.com/FriendsOfPHP/Goutte. I want to parse single value from a website using following code:

$client = new Client();
$crawler = $client->request('GET', 'https://mig.kz');

$crawler->filter('.buy')->eq(0)->each(function ($node) {                                                                                                                                                
   echo $node->text();                                                                                                                                                                                       
});

I can get a single value using each(), but is this possible without each? How can i store the first matching value in a variable, then reuse it later?



via Alexander Kim

Advertisement