FriendsOfPHP / Goutte

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

Return value of Symfony\Component\DomCrawler\Crawler::createSubCrawler() must be an instance of Symfony\Component\DomCrawler\object, instance of Symfony\Component\DomCrawler\Crawler returned #408

Closed marionava closed 4 years ago

marionava commented 4 years ago

Hi, I don't know why on my lap everything is working fine and on my server I'm getting this error:

Return value of Symfony\Component\DomCrawler\Crawler::createSubCrawler() must be an instance of Symfony\Component\DomCrawler\object, instance of Symfony\Component\DomCrawler\Crawler returned

Captura de Pantalla 2020-01-31 a la(s) 18 20 25

My code is on a Laravel Controller

use Goutte\Client;

class DashboardController extends Controller
{
public function getDolarHoy()
    {
        $client = new Client();
        $crawler = $client->request('GET', 'https://www.eldolar.info/es-MX/mexico/dia/hoy');
        $dolarhoy = $crawler->filter('table#dllsTable>tbody>tr>td.xTimes')->eq(1)->text();

        return $dolarhoy;
    }
}

The error is on the second line of the function.

On my server I have php 7.2.26 I'm using "fabpot/goutte": "^4.0"

fabdelgado commented 4 years ago

Hi, I've try and it' works in Laravel.

use Goutte\Client as Client;

$client = new Client(); $crawler = $client->request('GET', 'https://www.eldolar.info/es-MX/mexico/dia/hoy'); $dolarhoy = $crawler->filter('table#dllsTable>tbody>tr>td.xTimes')->eq(1)->text();

echo $dolarhoy;

marionava commented 4 years ago

I've reviewed the php server version an is 7.1.24.

Is this the bug reason?

marionava commented 4 years ago

Yes, the php version (7.1.*) is the reason...

It would be great if you edit your Readme.rst to

Goutte depends on PHP 7.2+.

If somebody else experienced this bug and can't change the php version like on my case. I changed the Crawler.php file of Symphony

from this

private function createSubCrawler($nodes): object

to this

private function createSubCrawler($nodes)

I know this is not a good practice, but I have not choice.