Skip to content

Scraper-APIs/milanuncios-scraper-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Milanuncios Scraper PHP

Biblioteca PHP para extraer anuncios clasificados de Milanuncios — el mayor portal de compraventa de segunda mano en Espana. Obtiene datos estructurados con precios, atributos, fotos, ubicacion e informacion del vendedor.

Funciona con Apify como motor de scraping.

Instalacion

composer require scraper-apis/milanuncios-scraper

Inicio rapido

use MilanunciosScraper\Client;

$client = new Client('tu_token_apify');

$anuncios = $client->scrape(
    text: 'iPhone 15 Pro',
    maxResults: 50,
);

foreach ($anuncios as $anuncio) {
    echo "{$anuncio->title}\n";
    echo "Precio: {$anuncio->getPriceAmount()} {$anuncio->getCurrency()}\n";
    echo "Fotos: {$anuncio->imageCount}\n";

    if ($anuncio->isShippable()) {
        echo "Envio disponible\n";
    }

    if ($anuncio->isProfessionalSeller()) {
        echo "Vendedor profesional\n";
    }
}

Parametros

use MilanunciosScraper\SortOrder;
use MilanunciosScraper\SellerType;
use MilanunciosScraper\Transaction;

$anuncios = $client->scrape(
    text: 'bicicleta electrica',
    category: 'bicicletas',
    maxResults: 200,
    sort: SortOrder::Cheap,
    priceFrom: 500,
    priceTo: 3000,
    isShippable: true,
    sellerType: SellerType::Private,
    transaction: Transaction::Supply,
);
Parametro Tipo Por defecto Descripcion
text ?string null Texto de busqueda
category ?string null Categoria
maxResults int 0 Max anuncios (0 = sin limite)
sort SortOrder Relevance Orden de resultados
priceFrom ?int null Precio minimo (EUR)
priceTo ?int null Precio maximo (EUR)
isShippable bool false Solo con envio
sellerType SellerType All Tipo de vendedor
transaction Transaction All Tipo de transaccion

Enumeraciones

Enum Valores
SortOrder Relevance, Newest, Cheap, Expensive
SellerType All, Professional, Private
Transaction All, Supply (venta), Demand (busqueda)

Que obtienes por anuncio

Cada Listing incluye: title, description, price (con amount y currency), photos, location, categories, attributes (pares clave-valor con formato raw/formatted), authorId, authorName, publicationDate, shipping, shop

Metodos utiles:

$anuncio->getPriceAmount();     // precio como float
$anuncio->getCurrency();        // "EUR"
$anuncio->getAttribute('km');   // valor formateado de un atributo
$anuncio->getAttributeRaw('km');// valor raw de un atributo
$anuncio->isShippable();        // tiene envio disponible
$anuncio->isProfessionalSeller(); // vendedor profesional (tienda)

Manejo de errores

use MilanunciosScraper\Exception\ApiException;
use MilanunciosScraper\Exception\RateLimitException;

try {
    $anuncios = $client->scrape(text: 'coche');
} catch (RateLimitException $e) {
    sleep($e->retryAfter);
} catch (ApiException $e) {
    echo "Error API: {$e->getMessage()}\n";
}

Requisitos

Licencia

MIT

Releases

No releases published

Packages

No packages published

Languages