这就是我的HTML的样子:
<div class="academy_page">
<span class="academy_page_header">Academy:</span>
<div>
<div class="videopage_block" align="center">
<iframe class="videopage_video" src="//player.vimeo.com/video/67353453644?title=0&byline=0&portrait=0" width="300" height="150" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
<div class="academy_text">How to Ride a Skateboard</div>
</div>
<div class="videopage_block" align="center">
<iframe class="videopage_video" src="//player.vimeo.com/video/9435345343?title=0&byline=0&portrait=0" width="300" height="150" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
<div class="academy_text">How to Build a Skateboard</div>
</div>
</div>
这就是我解析它的方式:
foreach($html->find('div.academy_page') as $element){
foreach($element->find('div.videopage_block') as $dulce) {
$item['title'] = $dulce->find('div.academy_text', 0)->plaintext;
$item['vimeo_url'] = $dulce->find('iframe')->src;
$returnArray[] = $item;
}
}
这是我在json中的结果:
[
{
"title": "How to Ride a Skateboard",
"vimeo_url": null
},
{
"title": "How to Build a Skateboard",
"vimeo_url": null
}
]
如何获取iFrame SRC?
我还试过$item['vimeo_url'] = $dulce->find('.videopage_video')->plaintext;
而没有
答案 0 :(得分:1)
我想你可以使用:
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
foreach ($xpath->query("//div[@class='videopage_block']") as $node){
echo $node->getElementsByTagName('iframe')[0]->getAttribute("src");
echo $node->getElementsByTagName('div')[0]->nodeValue;
}
<强>更新强>
获取视频ID:
$iframe_src = $node->getElementsByTagName('iframe')[0]->getAttribute("src")
$video_id = preg_replace('%.*?video/(\d+)\?.*%i', '$1', $iframe_src);
答案 1 :(得分:0)