Skip to content

Instantly share code, notes, and snippets.

@jsstoni
Created October 22, 2021 12:33
Show Gist options
  • Save jsstoni/6bd34e6337ff04e68f4bd56f40f773f0 to your computer and use it in GitHub Desktop.
Save jsstoni/6bd34e6337ff04e68f4bd56f40f773f0 to your computer and use it in GitHub Desktop.
Mercadolibre chile
<?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