user1947455 user1947455 - 3 months ago 24
PHP Question

php simple dom parser how to grab iframe from a class

I am having issues getting the correct iframes from a site.

Here is the code i am trying to use. The problem im having is this returns everything in the content class. I would like to return only the iframes that are located in the class. Any help would be appreciated. Thank you.

<?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.5\r\n"
)
);

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

?>

Answer

Ok so i figured it out.

<?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);

?>