Alguem pode ajudar? plss
<?php
namespace OliveiraJulia\buscador;
require "vendor/autoload.php";
use GuzzleHttp\Client;
use Symfony\Component\DomCrawler\Crawler;
class buscador
{
private $httpClient;
private $crawler;
public function __construct (clientInterface $httpClient, Crawler $crawler)
{
$this->httpClient = $httpClient;
$this->crawler = $crawler;
}
public function buscar($url): array
{
$resposta = $this->httpClient->request('GET', $url);
$html = $resposta->getBody();
$this->crawler->addHtmlContent($html);
$elementoCursos = $this->crawler->filter('span.card-curso__nome');
$cursos = [];
foreach ($elementoCursos as $elemento){
$cursos [] = $elemento->textContent;
}
return $cursos;
}
}
<?php
require "vendor/autoload.php";
use GuzzleHttp\Client;
use Symfony\Component\DomCrawler\Crawler;
$client = new Client(["base_uri" => "https://www.alura.com.br/" ], ['verify' => false]);
$buscador = new Buscador($client, $crawler);
$cursos = $buscador->buscar("/cursos-online-design-ux");
foreach ($cursos as $curso) {
echo $curso . PHP_EOL;
}
{
"name": "oliveira-julia/buscador-cursos",
"type": "library",
"autoload": {
"psr-4": {
"OliveiraJulia\\BuscadorCursos\\": "src/"
}
},
"authors": [
{
"name": "Julia",
"email": "juliapereiraengc@gmail.com"
}
],
"require": {
"guzzlehttp/guzzle": "^7.4",
"symfony/dom-crawler": "^6.1",
"symfony/css-selector": "^6.1"
}
}