synan54 synan54 - 1 year ago 152
PHP Question

Get IFrame src with SimpleHTMLDOM parser

hi i was working on a scrapper but i am unable to get one of information.

this is the link

div class="video_container">
<div class="video_object">
<iframe id="player" width="100%" height="100%" frameborder="0" allowfullscreen="1" title="YouTube video player"
src=" color=white&rel=0&wmode=transparent&modestbranding=1&theme=light&autohide=1&start=4&">
<!DOCTYPE html>
<html lang="en" data-cast-api-enabled="true" dir="ltr"

i need src =""

i this is my code which does not work

foreach ($html->find('.video_object')as $iframe){
echo "this is video ".$iframe->outertext ." <br>";

thank you very uc

Answer Source

Do this return anything on your code?

$html->find('.video_object iframe')

If so, try using ->getAttribute('src'); it might work.

For further information take a look at PHP DOMElement


Use XPath instead, it will output the expected result

//init DOMDocument
$dom = new DOMDocument();
//get the source from the URL
$html = file_get_contents("URL");
//load the html from html string
//init XPath
$xpath = new DOMXPath($dom);

//fetch the src from the iframe within

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download