Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从DOM中按标记或类名提取元素_Php_Parsing_Html Content Extraction - Fatal编程技术网

Php 从DOM中按标记或类名提取元素

Php 从DOM中按标记或类名提取元素,php,parsing,html-content-extraction,Php,Parsing,Html Content Extraction,我尝试使用类PHP简单HTML DOM解析器按类名提取图像,但我无法做到这一点 我使用这个类: $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->

我尝试使用类PHP简单HTML DOM解析器按类名提取图像,但我无法做到这一点

我使用这个类:

$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; 
但是我不能得到这个,我不知道我是否可以用其他类或函数得到这个,有可能得到吗,谢谢,假设“屏幕截图”是图像的类名:

foreach($html->find('img.screenshot')作为$img){
//用$img做你想做的事
}


你应该阅读

,例如,提取youtube视频的url:Regardso这样的方法会起作用:
foreach($html->find('.preview overlay container')as$video){$url=$video->getAttribute('data-video-url');}
谢谢很多我了解它的工作原理,很好,谢谢你的帮助