0

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

error message

I use laravel 2.2.29

1

1 Answer 1

2

Your filterdid 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..
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.