Reputation: 35
why when I execute the code in the document of the laravel-goutte it doesn't work , that code is in the main page of the package on github:
https://github.com/dweidner/laravel-goutte
use Weidner\Goutte\GoutteFacadeGoutte;
Route::get('/', function() {
$crawler = Goutte::request('GET', 'http://duckduckgo.com/?q=Laravel');
$url = $crawler->filter('.result__title > a')->first()->attr('href');
dump($url);
return view('welcome');
});
and shows that error
I use laravel 2.2.29
Upvotes: 0
Views: 1010
Reputation: 12186
Your filter
did not return any results. That is why it crashed. That's how I solved this issue, by adding a try catch.
try {
$url = $crawler->filter('.result__title > a')->first()->attr('href');
} catch (\InvalidArgumentException $e) {
// Handle the current node list is empty..
}
Upvotes: 2