如何从给定的网站使用php file_get_content输出以下div的SRC?
<div class="videocontainer">
<input type="file" id="srtSelector"/>
<video class="video-js vjs-default-skin vjs-big-play-centered" id="olvideo">
<track kind="captions" src="https://rolled.oped.info/sub/jAghd9t8AB4/HfQZ32SovcY.vtt"/>
</video>
</div>我对显示https://rolled.oped.info/sub/jAghd9t8AB4/HfQZ32SovcY.vtt部件感兴趣。
谢谢!
发布于 2018-05-27 06:53:34
最好是尝试使用DOM,而不是使用regex等。DOMDocument并不总是简单的使用,但是对于您的问题,它可能会完成工作……
$html = <<< HTML
<div class="videocontainer">
<input type="file" id="srtSelector"/>
<video class="video-js vjs-default-skin vjs-big-play-centered" id="olvideo">
<track kind="captions" src="https://rolled.oped.info/sub/jAghd9t8AB4/HfQZ32SovcY.vtt"/>
</video>
</div>
HTML;
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$tracks = $dom->getElementsByTagName("track");
foreach ( $tracks as $track ) {
echo (string)$track->getAttribute("src").PHP_EOL;
}代码应该足够容易遵循。
您可以面对的最大问题是,如果HTML有错误(如问题中的原始错误),那么有时这会使加载变得困难。
https://stackoverflow.com/questions/50549559
复制相似问题