Php 从DOM中按标记或类名提取元素
我尝试使用类PHP简单HTML 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->
$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');}
谢谢很多我了解它的工作原理,很好,谢谢你的帮助