【问题标题】:Extract elements by tag or class name from DOM从 DOM 中按标签或类名提取元素
【发布时间】:2014-07-17 15:22:14
【问题描述】:

我尝试使用类 PHP Simple HTML DOM Parser 按类名提取图像,但我无法得到这个

我在这个类中使用这个:

$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; 

但是我不能得到这个我不知道我是否可以用其他类或函数来做到这一点,有可能得到吗? ,谢谢,问候

【问题讨论】:

    标签: php parsing html-content-extraction


    【解决方案1】:

    假设“截图”是图像的类名:

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

    您应该阅读documentation

    【讨论】:

    • 例如提取youtube视频的url: youtube.com/embed/…"> 问候
    • 这样的事情会起作用:foreach ($html->find('.preview-overlay-container') as $video) { $url = $video->getAttribute('data-video-url'); }
    • 非常感谢,我了解它的工作原理,很好,感谢您的帮助
    猜你喜欢
    • 2019-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    • 2011-09-16
    相关资源
    最近更新 更多