1
Hello, I’m trying to get data from a website to an internal system I’m creating through PHP I’m using the DOM for this.
I was able to find all the information in his html, but I’m not able to filter.
My code:
<?php
// Create DOM from URL or file
include 'simple_html_dom.php';
echo file_get_html('http://www.site.com.br/')->plaintext;
$html = file_get_html('http://www.site.com.br/');
// Aqui está meu erro
foreach($html->find('main') as $element)
echo $element->select . '<br>';
// Find all links
//foreach($html->find('a') as $element)
// echo $element->href . '<br>';
?>
My website returns:
Concordia Herval Erechim Kaiser lata 350ml R$ 1,69 /cada Costela grossa resfriada R$ 11,99 /kg Açúcar cristal Guarani 5kg R$ 6,95 /cada Leite longa vida Terra Viva 1L R$ 2,09 /cada Filé americano R$ 14,99 /kg Coxa com sobrecoxa dorsal R$ 3,99 /kg Cerveja Bohemia lata 350ml R$ 1,99 /cada Filé simples R$ 17,99 /kg Alcatra com osso R$ 21,90 /kg Kaiser lata 350ml R$ 1,69 /cada Costela grossa resfriada R$ 11,99 /kg Sabão em pó Omo multi ação 2kg R$ 13,99 /cada Leite longa vida Tirol 1L R$ 2,19 /cada Alcatra com osso R$ 21,90 /kg Carré suíno com pele resfriado R$ 10,90 /kg Filé simples R$ 17,90 /kg Budweiser lata 350ml R$ 2,79 /cada Leite condensado Tirol 395g R$ 2,79 /cada Cerveja Dado Bier latão 473ml R$ 2,79 /cada Alcatra sem osso R$ 24,90 /kg Coca-Cola 2L R$ 5,49 /cada Leite condensado Tirol 395g R$ 2,89 /cada Costela suína com pele resfriada R$ 9,90 /kg Cerveja Lokal latão 473ml R$ 1,89 /cada Açúcar cristal Gasparin 5kg R$ 7,99 /cada Fraldinha bovina Montana R$ 19,90 /kg Filé americano R$ 15,90 /kg Acesse nosso tablóide de ofertas
But I would like to take only from my city which is Erechim, which would start in Given Beer.
The structure of the site is like this:
<main id="main" class="site-main" role="main">
<select id="cidade-ofertas">
<option value="cidade-concordia">Concordia</option>
<option value="cidade-herval">Herval</option>
<option value="cidade-erechim">Erechim</option>
</select>
<div class="products-slider cidade-erechim">
<div class="item">
<header class="item-header">
<div class="item-thumb">
<img width="160" height="160" src="http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy-160x160.png" class="attachment-home_product size-home_product wp-post-image" alt="" srcset="http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy-160x160.png 160w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy-150x150.png 150w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy-300x300.png 300w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy-180x180.png 180w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy-40x40.png 40w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy-60x60.png 60w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/cerveja-dadobier-lata-473ml-copy.png 400w" sizes="(max-width: 160px) 100vw, 160px" />
<h4 class="item-title">Cerveja Dado Bier latão 473ml</h4>
</div><!-- .item-thumb -->
<p class="item-description">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">R$</span>2,79</span></span> <span class="detail">/cada</span>
</p><!-- .item-description -->
</header><!-- .item-header -->
</div><!-- .item -->
<div class="item">
<header class="item-header">
<div class="item-thumb">
<img width="160" height="160" src="http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso-160x160.png" class="attachment-home_product size-home_product wp-post-image" alt="" srcset="http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso-160x160.png 160w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso-150x150.png 150w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso-300x300.png 300w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso-40x40.png 40w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso-60x60.png 60w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso.png 400w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/alcatra-sem-osso-100x100.png 100w" sizes="(max-width: 160px) 100vw, 160px" />
<h4 class="item-title">Alcatra sem osso</h4>
</div><!-- .item-thumb -->
<p class="item-description">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">R$</span>24,90</span></span> <span class="detail">/kg</span>
</p><!-- .item-description -->
</header><!-- .item-header -->
</div><!-- .item -->
<div class="item">
<header class="item-header">
<div class="item-thumb">
<img width="160" height="160" src="http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4-160x160.png" class="attachment-home_product size-home_product wp-post-image" alt="" srcset="http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4-160x160.png 160w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4-150x150.png 150w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4-300x300.png 300w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4-180x180.png 180w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4-40x40.png 40w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4-60x60.png 60w, http://www.superpassarela.com.br/wp-content/uploads/2017/12/Coca-Cola-2-litros-4.png 400w" sizes="(max-width: 160px) 100vw, 160px" />
<h4 class="item-title">Coca-Cola 2L</h4>
</div><!-- .item-thumb -->
<p class="item-description">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">R$</span>5,49</span></span> <span class="detail">/cada</span>
</p><!-- .item-description -->
</header><!-- .item-header -->
</div><!-- .item -->
<div class="item">
<header class="item-header">
<div class="item-thumb">
<img width="160" height="160" src="http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395-160x160.png" class="attachment-home_product size-home_product wp-post-image" alt="" srcset="http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395-160x160.png 160w, http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395-150x150.png 150w, http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395-300x300.png 300w, http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395-180x180.png 180w, http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395-40x40.png 40w, http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395-60x60.png 60w, http://www.superpassarela.com.br/wp-content/uploads/2018/01/leite-condensado-tirol-tp395.png 400w" sizes="(max-width: 160px) 100vw, 160px" />
<h4 class="item-title">Leite condensado Tirol 395g</h4>
</div><!-- .item-thumb -->
<p class="item-description">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">R$</span>2,89</span></span> <span class="detail">/cada</span>
</p><!-- .item-description -->
</header><!-- .item-header -->
</div><!-- .item -->
<div class="item">
<header class="item-header">
<div class="item-thumb">
<img width="160" height="160" src="http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina-160x160.png" class="attachment-home_product size-home_product wp-post-image" alt="" srcset="http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina-160x160.png 160w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina-150x150.png 150w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina-300x300.png 300w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina-40x40.png 40w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina-60x60.png 60w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina.png 400w, http://www.superpassarela.com.br/wp-content/uploads/2018/09/costela_suina-100x100.png 100w" sizes="(max-width: 160px) 100vw, 160px" />
<h4 class="item-title">Costela suína com pele resfriada</h4>
</div><!-- .item-thumb -->
<p class="item-description">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">R$</span>9,90</span></span> <span class="detail">/kg</span>
</p><!-- .item-description -->
</header><!-- .item-header -->
</div><!-- .item -->
<div class="item">
<header class="item-header">
<div class="item-thumb">
<img width="160" height="160" src="http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1-160x160.png" class="attachment-home_product size-home_product wp-post-image" alt="" srcset="http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1-160x160.png 160w, http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1-150x150.png 150w, http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1-300x300.png 300w, http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1-40x40.png 40w, http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1-60x60.png 60w, http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1.png 400w, http://www.superpassarela.com.br/wp-content/uploads/2018/10/cerveja-lokal-1-100x100.png 100w" sizes="(max-width: 160px) 100vw, 160px" />
<h4 class="item-title">Cerveja Lokal latão 473ml</h4>
</div><!-- .item-thumb -->
<p class="item-description">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">R$</span>1,89</span></span> <span class="detail">/cada</span>
</p><!-- .item-description -->
</header><!-- .item-header -->
</div><!-- .item -->
<div class="item">
<header class="item-header">
<div class="item-thumb">
<img width="160" height="160" src="http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin-160x160.png" class="attachment-home_product size-home_product wp-post-image" alt="" srcset="http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin-160x160.png 160w, http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin-150x150.png 150w, http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin-300x300.png 300w, http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin-40x40.png 40w, http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin-60x60.png 60w, http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin.png 400w, http://www.superpassarela.com.br/wp-content/uploads/2018/08/açucar-gasparin-100x100.png 100w" sizes="(max-width: 160px) 100vw, 160px" />
<h4 class="item-title">Açúcar cristal Gasparin 5kg</h4>
</div><!-- .item-thumb -->
<p class="item-description">
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">R$</span>7,99</span></span> <span class="detail">/cada</span>
</p><!-- .item-description -->
</header><!-- .item-header -->
</div><!-- .item -->
How do I display Product Name and Price? I’m not getting on track to filter
Give me the website link
– Bulfaitelo
if you can open a chat, here I think it would not be nice
– Ricardo Gonçalves
really, just use the Cheerio if possible, much better than php for this kind of thing. Even if only to play on a spreadsheet or similar and then consume it in php. Even more direct in the DOM class is more Roots yet.
– Neuber Oliveira