PHP简单dom解析器如何从类中抓取iframe



我有问题从一个网站获得正确的iframe。

这是我试图使用的代码。我遇到的问题是,这会返回content类中的所有内容。我想只返回位于类中的iframe。任何帮助都会很感激。谢谢你。

<?php
include_once('../../simple_html_dom.php');
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5rn"
)
);
$context = stream_context_create($opts);
$html = file_get_html('http://www.tvshow7.eu/breaking-bad-season-1-episode-1-pilot/', false, $context);
foreach($html->find('.content') as $iframe) {
echo $iframe->outertext, PHP_EOL;
}
?>    

好吧,我明白了。

<?php
include_once('../../simple_html_dom.php');

$html = file_get_html('http://www.tvshow7.eu/breaking-bad-season-1-episode-1-pilot/');
// find <p> and store varible
foreach($html->find('p') as $p)
// find iframe from within varibale $p
foreach($p->find('iframe') as $iframe)
echo $iframe->outertext . '<p>';
 // clean up memory
    $html->clear();
    unset($html);
?>

最新更新