Skip to content

Instantly share code, notes, and snippets.

@jsstoni
Last active August 26, 2021 14:37
Show Gist options
  • Save jsstoni/79c6da7545ae9ab0dcd3e322d94de7cf to your computer and use it in GitHub Desktop.
Save jsstoni/79c6da7545ae9ab0dcd3e322d94de7cf to your computer and use it in GitHub Desktop.
scraping mercado libre
<?php
require_once 'simple_html_dom.php';
$id = $_GET['id']; //_CustId_328224676
if (isset($id)) {
$url = "https://listado.mercadolibre.cl/{$id}";
$html = file_get_html($url);
$productos = array();
foreach ($html->find("ol.ui-search-layout", 0)->find("li.ui-search-layout__item") as $key => $li) {
$items = array();
$items['title'] = $li->find('h2.ui-search-item__title', 0)->plaintext;
$precio = $li->find('span.price-tag-fraction', 0)->plaintext;
$items['price'] = $precio;
$items['image'] = $li->find('img.ui-search-result-image__element', 0)->{'data-src'};
$productos[] = $items;
}
foreach ($productos as $key => $item) {
echo "<p>".$item['title']."</p>";
echo "<p>".$item['price']."</p>";
echo "<img src=\"".$item['image']."\" width=\"150\">";
echo "<hr>";
}
}else {
echo "Ingrese el id del cliente";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment