0

我在 symfony 中使用 panther从网站上抓取数据检测到我的 chromedriver。但我收到此错误消息“30 秒后无法连接到 chrome(“http://127.0.0.1:9515/status”已达到超时。)。我试图更改端口但没有。

在 CLI 中:“警告:fsockopen():无法连接到 127.0.0.1:9515”

如果有人有想法我很感兴趣!提前致谢 !

我的代码:

<?php
namespace App\Service;

use InvalidArgumentException;
use \Symfony\Component\Panther\Client;
use Symfony\Component\HttpKernel\KernelInterface;

class ScraperService {

    private $appKernel;

    public function __construct(KernelInterface $appKernel)
    {
        $this->appKernel = $appKernel;
    }
    
    public function getDataFromCarrefour(){

        $path = $this->appKernel->getProjectDir().'/drivers\chromedriver.exe';

        $results = array();
        $client = Client::createChromeClient($path, [
            '--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3312.0 Safari/537.36"',
            '--headless',
        ]);

        $crawler = $client->request('GET', 'https://www.carrefour.fr/p/*-3600900006972');

   try{
        $results['ingredients'] = $crawler->filter('#product-detail-page > div.pdp__secondary > div > div > div.secondary-details__left > div.secondary-details-blocks > div:nth-child(4) > div > p')->text(); 
        $results['images'] = $crawler->filter('#data-produit-image > div > div.carousel__wrapper > div.carousel__siema > div > div:nth-child(1) > div > div > img')->attr('src');
        $results['title'] = $crawler->filter('#data-produit-card > div.main-details__pricing > div > div > div > div.pdp-pricing__block-left > div.product-card-price > div > span')->text();
        $results['score'] = $crawler->filter('#data-produit-card > div.main-details__scores > a.product-badge__link.product-badge--flag-nutriscore > picture > img')->attr('src');
        
    }catch (InvalidArgumentException $e){
            dd($e);
            $results['error'] = 'EAN unreconized !';
        }
        $client->close();
        
        return $results;
    }
}
?>

“C:\Users\gelinn\Desktop\base-veille\vendor\symfony\panther\src\ProcessManager\WebServerReadinessProbeTrait.php”中的 RuntimeExeption(第 82 行):

if ($e) {          
        $message = $e->getMessage();              
    } else {                
        $message = "Status code: $statusCode";        
    }            
    throw new \RuntimeException("Could not connect to $service after $timeout seconds ($message).");          
    }           
    usleep(1000);   
4

0 回答 0