FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Fatal error: Default value for parameters with a class type hint can only be NULL in C:\xampp5\htdocs\goutte\vendor\symfony\browser-kit\Client.php on line 275 #331

Closed Aslam97 closed 3 years ago

Aslam97 commented 6 years ago

I did the same as the documentation explain but I dont know why I am getting this error. I use php 5.6 here's my code

<?php 

require 'vendor/autoload.php';

use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;

$goutteClient = new Client();
$guzzleClient = new GuzzleClient(array(
    'timeout' => 60,
));
$goutteClient->setClient($guzzleClient);

$crawler = $goutteClient->request('GET', "http://carikodepos.com/daerah/dki-jakarta/page/14/"); 

$news = $crawler->filterXPath('//table')->filter('tr')->each(function ($tr, $i) { return $tr->filter('td')->each(function ($td, $i) { return trim($td->text()); }); });

print_r($news);

 ?>

can any one please tell me why I am getting this error ? and so how do I fix this error ?

dv336699 commented 6 years ago

Goutte relies on brower-kit which by default installs version 4 which is only compatible with PHP 7.1 and above.

composer require symfony/browser-kit 3.4.4 because you're probably using PHP < 7.1

dv336699 commented 6 years ago

The last compatible version with PHP 5.6 is 3.2.1 composer require fabpot/goutte 3.2.1

balazs1396 commented 6 years ago

If I write that command what you are offer, one other problem happening. You know, that its download automatically the symfony component, but if you have php 5.6 it cant't download because you get a error message on a command line like : untitled

dv336699 commented 6 years ago

composer require --ignore-platform-reqs fabpot/goutte 3.2.1

balazs1396 commented 6 years ago

composer require --ignore-platform-reqs fabpot/goutte 3.2.1

THANK YOU :)