1
resposta

Undefined type 'GuzzleHttp\Client'

<?php require 'vendor/autoload.php';

use GuzzleHttp\Client; use Symfony\Component\DomCrawler\Crawler;

$client = new Client(); $resposta = $client->request('GET', 'https://www.alura.com.br/cursos-online-programacao/php');

$html = $resposta->getBody();

$crawler = new Crawler(); $crawler->addHtmlContent($html);

$cursos = $crawler->filter('span.card-curso__nome');

foreach ($cursos as $curso) { echo $curso->textContent . PHP_EOL; }

erro no cmd

C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura>composer require symfo ny / css-selector

[InvalidArgumentException] Could not find package symfony.

Did you mean one of these? symfony/finder symfony/routing symfony/process symfony/console symfony/symfony

require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--fixed] [--no-su ggest] [--no-progress] [--no-update] [--no-install] [--no-scripts] [--update-no- dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with -dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM- REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packag es] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] []...

C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura> php buscar-cursos.php

PHP Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://cu rl.haxx.se/libcurl/c/libcurl-errors.html) for https://www.alura.com.br/cursos-on line-programacao/php in C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alur a\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:211 Stack trace:

#0 C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\g uzzle\src\Handler\CurlFactory.php(158): GuzzleHttp\Handler\CurlFactory::createRe jection(Object(GuzzleHttp\Handler\EasyHandle), Array)

#1 C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\g uzzle\src\Handler\CurlFactory.php(110): GuzzleHttp\Handler\CurlFactory::finishEr ror(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle ), Object(GuzzleHttp\Handler\CurlFactory))

#2 C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\g uzzle\src\Handler\CurlHandler.php(47): GuzzleHttp\Handler\CurlFactory::fi in C:Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\guzzlesrc\Handler\CurlFactory.php on line 211

Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.ha xx.se/libcurl/c/libcurl-errors.html) for https://www.alura.com.br/cursos-online- programacao/php in C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\ven dor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:211 Stack trace:

#0 C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\g uzzle\src\Handler\CurlFactory.php(158): GuzzleHttp\Handler\CurlFactory::createRe jection(Object(GuzzleHttp\Handler\EasyHandle), Array)

#1 C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\g uzzle\src\Handler\CurlFactory.php(110): GuzzleHttp\Handler\CurlFactory::finishEr ror(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle ), Object(GuzzleHttp\Handler\CurlFactory))

#2 C:\Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\g uzzle\src\Handler\CurlHandler.php(47): GuzzleHttp\Handler\CurlFactory::fi in C:Users\gb2020\Documents\Alura\PHP\buscador-cursos-alura\vendor\guzzlehttp\guzzlesrc\Handler\CurlFactory.php on line 211

1 resposta

Boa tarde, Aconteceu o mesmo comigo, você precisa baixar http://curl.haxx.se/ca/cacert.pem recomendo colocar esse arquivo no mesmo diretório do PHP para facilitar as coisas depois de baixado o arquivo você vai até o arquivo php.ini e adiciona o seguinte trecho de código

;;;;;;;;;;;;;;;;;;;;
; php.ini Options  ;
;;;;;;;;;;;;;;;;;;;;

curl.cainfo = "Caminho do arquivo cacart.pem\cacert.pem"