How to get alt attribute from a specific div image by php scraper ? Just look my following code sample. I can print all img "alt" attribute. But I would like to get the "alt" attribute of a specific div class. How can? Here is my code sample:
<?php
error_reporting(E_ALL);
error_reporting(1);
set_time_limit(0);
require 'simple_html_dom.php';
$url = "mylink.com";
$html = file_get_html($url);
foreach($html->find('img') as $element)
echo $element->alt.'<br>';
?>
Let's say the div's class is foo
:
foreach($html->find('div.foo') as $div) {
echo $div->alt . '<br>';
}