" <?php
namespace Alura\BuscadorDeCursos;
class Buscador{
private $httpClient; private $crawler;
public function __construct( $httpClient, $crawler)
{
$this->httpClient = $httpClient;
$this->crawler = $crawler;
}
function buscar ($url){
$resposta = $this->httpClient->request('GET',$url) ;
$html = $resposta->getBody();
$this->crawler->addHtmlContent($html);
$cursos = $this->crawler->filter('span.card-curso__nome');
$elementos = [];
foreach ($cursos as $curso){
$elementos [] =$curso->textContent . PHP_EOL;
}
return $elementos;
}
'https://www.alura.com.br/']);
$crawler = new Crawler();
$buscador = new Buscador($client,$crawler);
$cursos = $buscador->buscar('/cursos-online-programacao/php');
foreach($cursos as $curso){
echo $curso . PHP_EOL; echo""; } ?>
{ "name": "alura/buscador", "description": "buscador de cursos", "type": "library", "license": "MIT",
"authors": [
{
"name": "keke",
"email": "xxxx@hotmail.com"
}
],
"require": {
"guzzlehttp/guzzle": "^6.5",
"symfony/dom-crawler": "^5.1",
"symfony/css-selector": "^5.1"
},
"autoload": {
"psr-4": {
"Alura\\BuscadorDeCursos\\": "src/"
}
}
} "