【问题标题】:Get Embed Video ID from Within Rumble.com HTML从 Rumble.com HTML 中获取嵌入视频 ID
【发布时间】:2020-11-16 18:18:19
【问题描述】:

尝试从此页面提取视频 ID: https://rumble.com/vb5dyh-space-x-we-have-lift-off.html

具体来说,通配符值在该页面的源代码中如下:

Rumble("play", {"rel":1,"resize":"auto16:9","opts":["skip_ga_load"],"video":"v8j7rt","div":"videoPlayer"});

我试图在这个例子中提取的值是:v8j7rt

嵌入代码需要此 ID。

我正在试验的示例 PHP 代码:

require_once 'simple_html_dom.php';
$url = 'https://rumble.com/vb5dyh-space-x-we-have-lift-off.html';
$html = file_get_contents( $url );
$dom  = new DOMDocument();
$pattern='"video":"(.*?)"';
// $pattern='\"video\":\"(.*?)\"';
preg_match($pattern,$dom,$match);

print_r($match);

似乎无法提取此值。这是正确的方法吗?如果是这样,我在模式上做错了什么。

【问题讨论】:

    标签: php preg-match file-get-contents simple-html-dom


    【解决方案1】:

    不用DOMDocument()解析原始数据!

    您的正则表达式有问题,见下文:

    <?php
    $url = 'https://rumble.com/vb5dyh-space-x-we-have-lift-off.html';
    $html = file_get_contents( $url );
    preg_match('/"video\":\"(.*?)"/',$html,$match);
    
    print_r($match);
    
    // Array
    // (
    //  [0] => "video":"v8j7rt"
    //  [1] => v8j7rt
    // )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-28
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多