Search code examples
phpparsinghtml-content-extraction

Extract elements by tag or class name from DOM


I try use class PHP Simple HTML DOM Parser for extract images by class name but i can´t get this

I use this wth this class :

$file=file_get_contents("https://play.google.com/store/apps/details?id=com.cleanmaster.mguard&hl=en");

$html = str_get_html($file);

$html->find('img', 1)->class = 'screenshot';

//$html->find('div[id=hello]', 0)->innertext = 'foo';

echo $html; 

But i can´t get this i don´t know if i can do this with other class or functions , it´s possible get ? , thank´s , regards


Solution

  • Assuming "screenshot" is the image's class name:

    foreach ($html->find('img.screenshot') as $img) { // do what you want with $img }

    You should read the documentation