Documentation Index Fetch the complete documentation index at: https://firecrawl-mog-search-exclude-include-domains.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Adicione sua chave de API ao arquivo .env:
FIRECRAWL_API_KEY = fc-YOUR-API-KEY
Adicione a entrada de configuração em config/services.php:
'firecrawl' => [
'api_key' => env ( 'FIRECRAWL_API_KEY' ),
'base_url' => env ( 'FIRECRAWL_API_URL' , 'https://api.firecrawl.dev/v2' ),
],
Crie uma classe de serviço
Crie app/Services/FirecrawlService.php:
<? php
namespace App\Services ;
use Illuminate\Support\Facades\ Http ;
class FirecrawlService
{
private string $apiKey ;
private string $baseUrl ;
public function __construct ()
{
$this -> apiKey = config ( 'services.firecrawl.api_key' );
$this -> baseUrl = config ( 'services.firecrawl.base_url' );
}
public function search ( string $query , int $limit = 5 ) : array
{
$response = Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/search" , [
'query' => $query ,
'limit' => $limit ,
]);
return $response -> json ();
}
public function scrape ( string $url , array $options = []) : array
{
$response = Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/scrape" , array_merge ([ 'url' => $url ], $options ));
return $response -> json ();
}
public function interact ( string $url , string $prompt , ? string $followUp = null ) : array
{
// 1. Fazer scraping para abrir uma sessão de navegador
$scrapeResult = $this -> scrape ( $url , [ 'formats' => [ 'markdown' ]]);
$scrapeId = $scrapeResult [ 'data' ][ 'metadata' ][ 'scrapeId' ];
// 2. Enviar o primeiro prompt
Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/scrape/{ $scrapeId }/interact" , [
'prompt' => $prompt ,
]);
// 3. Enviar o prompt de acompanhamento
$result = null ;
if ( $followUp ) {
$result = Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/scrape/{ $scrapeId }/interact" , [
'prompt' => $followUp ,
]) -> json ();
}
// 4. Encerrar a sessão
Http :: withToken ( $this -> apiKey )
-> delete ( "{ $this -> baseUrl }/scrape/{ $scrapeId }/interact" );
return $result ?? $scrapeResult ;
}
}
Crie app/Http/Controllers/FirecrawlController.php:
<? php
namespace App\Http\Controllers ;
use App\Services\ FirecrawlService ;
use Illuminate\Http\ Request ;
class FirecrawlController extends Controller
{
public function __construct ( private FirecrawlService $firecrawl ) {}
public function search ( Request $request )
{
$validated = $request -> validate ([ 'query' => 'required|string' ]);
return response () -> json (
$this -> firecrawl -> search ( $validated [ 'query' ], $request -> input ( 'limit' , 5 ))
);
}
public function scrape ( Request $request )
{
$validated = $request -> validate ([ 'url' => 'required|url' ]);
return response () -> json ( $this -> firecrawl -> scrape ( $validated [ 'url' ]));
}
public function interact ( Request $request )
{
$validated = $request -> validate ([
'url' => 'required|url' ,
'prompt' => 'required|string' ,
]);
return response () -> json (
$this -> firecrawl -> interact (
$validated [ 'url' ],
$validated [ 'prompt' ],
$request -> input ( 'followUp' )
)
);
}
}
Em routes/api.php:
use App\Http\Controllers\ FirecrawlController ;
Route :: post ( '/search' , [ FirecrawlController :: class , 'search' ]);
Route :: post ( '/scrape' , [ FirecrawlController :: class , 'scrape' ]);
Route :: post ( '/interact' , [ FirecrawlController :: class , 'interact' ]);
php artisan serve
# Fazer uma busca na web
curl -X POST http://localhost:8000/api/search \
-H "Content-Type: application/json" \
-d '{"query": "firecrawl web scraping"}'
# Fazer scraping de uma página
curl -X POST http://localhost:8000/api/scrape \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'
# Interagir com uma página
curl -X POST http://localhost:8000/api/interact \
-H "Content-Type: application/json" \
-d '{"url": "https://www.amazon.com", "prompt": "Search for iPhone 16 Pro Max", "followUp": "Click on the first result and tell me the price"}'
Documentação de busca Faça uma busca na web e obtenha o conteúdo completo da página
Documentação de scraping Todas as opções de scraping, incluindo formatos, ações e proxies
Documentação de interação Clique, preencha formulários e extraia conteúdo dinâmico
Referência da API Documentação completa da API REST