Good afternoon!
I need to get information that is contained in divs in an HTML.
HTML:
<div id="fundo_conteudo_noticia_setor" class="textogeral marrom">
<div id="data_noticia_setor" class="textogeral_bold verde">Data</div>
<div id="conteudo_noticia_setor">
<a href="noticia_interna.asp?id=13692" class="sublinhado verde">
<span class="titulo_destaque_bold verde">Título<br>
<span class="titulo_destaque verde">Categoria</span>
</span>
<br><br>
</a>
Resumo do conteúdo...
</div>
</div>
<div id="seta_noticia_setor"><i class="fa fa-angle-right fa-3x verde"></i></div>
</div>
And this is the PHP I'm using to get the info. However, by picking node $ result ['title'], it is returning child elements together.
if(!$data = file_get_contents("meusiteteste.com.br")){
$results = false;
}
else {
$html = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $data);
$doc = new DomDocument();
@$doc->loadHTML($html);
$xpath = new DomXpath($doc);
$entries = $xpath->query("//div[@id=\"conteudo_noticia_setor\"]");
$results = array();
foreach ($entries as $entry){
$node = $xpath->query("a/attribute::href", $entry);
$result['link'] = $node->item(0)->value;
echo $result['link'].'<br>';
$node = $xpath->query("a/span[contains(@class, 'titulo_destaque_bold')]", $entry);
$result['titulo'] = $node->item(0)->nodeValue;
echo $result['titulo'].'<br><br>';
}
}
You are printing: TitleCategory I would like to take the contents of the span that is contained inside, but I do not know how to proceed.