嗨,我正在研究刮刀,但我无法获得其中一条信息。
这是链接 http://sfglobe.com/?id=19110
div class="video_container">
<div class="video_object">
<iframe id="player" width="100%" height="100%" frameborder="0" allowfullscreen="1" title="YouTube video player"
src="http://www.youtube.com/embed/KMYrIi_Mt8A?enablejsapi=1&controls=1&showinfo=0& color=white&rel=0&wmode=transparent&modestbranding=1&theme=light&autohide=1&start=4& origin=http%3A%2F%2Fsfglobe.com">
<!DOCTYPE html>
<html lang="en" data-cast-api-enabled="true" dir="ltr"
我需要 src ="http://www.youtube.com/embed/KMYrIi_Mt8A....."
我这是我的代码,它不起作用
foreach ($html->find('.video_object')as $iframe){
echo "this is video ".$iframe->outertext ." <br>";
}
非常感谢UC
这会在你的代码上返回任何内容吗?
$html->find('.video_object iframe')
如果是这样,请尝试使用它可能起作用->getAttribute('src');
。
欲了解更多信息,请查看 PHP DOMElement
编辑
改用 XPath,它将输出预期的结果
//init DOMDocument
$dom = new DOMDocument();
//get the source from the URL
$html = file_get_contents("URL");
//load the html from html string
$dom->loadHTML($html);
//init XPath
$xpath = new DOMXPath($dom);
//fetch the src from the iframe within
$iframe_src=$xpath->query('//*[@class="CLASSNAME"]/iframe//@src');
vardump($iframe_src);