从脚本内部获取数据,并使用php将其传递给纯文本? [英] Get data from inside script and pass it to plain text with php?

查看:37
本文介绍了从脚本内部获取数据,并使用php将其传递给纯文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想从外部HTML页面的script标签内部获取数据,

Basically I want to get a data from inside the script tag from an external HTML page,

示例:

<script type="text/javascript">
var playerInstance = jwplayer("jwplayer");
    playerInstance.setup({
    id:'jwplayer',
    width: "100%",
    height: "100%",
    aspectratio: "16:9",
    fullscreen: "true",
    primary: 'html5',
    provider: 'http',
    autostart: false,
    sources: [{"type":"video/mp4","label":360,"file":"MY-VIDEO-LINK"},{"type":"video/mp4","label":480,"file":"MY-VIDEO-LINK"}],
});

我只想要黑色标记:>>来源: [{"type":"video/mp4","label":360,"file":"MY-VIDEO-LINK"},{"type":"video/mp4","label":480,"file":"MY-VIDEO-LINK"}]

I just want the black-marked: >> sources: [{"type":"video/mp4","label":360,"file":"MY-VIDEO-LINK"},{"type":"video/mp4","label":480,"file":"MY-VIDEO-LINK"}]

我可以使用PHP访问该页面:
$ url ='http://my-external-site.com/embed.php?url=blahblahblah';

I have access to the page using PHP:
$url = 'http://my-external-site.com/embed.php?url=blahblahblah';

我已经尝试了Curl,没有运气和DOM,几乎在那儿了:

I've tried Curl, no luck, and DOM, almost there:

include_once('simple_html_dom.php');
$html = file_get_html($url);
$elem = $html->find('sources', 0); //tried with 'sources' but probably is wrong
echo $elem;

感谢您的帮助,谢谢!

推荐答案

在不使用simple_html_dom的情况下尝试以下代码.编辑

Try this following code without simple_html_dom . EDITED

$url = 'YOUR_URL';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10');
$html = curl_exec($curl);
curl_close($curl);
$dom = new DOMDocument();
@$dom->loadHTML($html);  //convert character asing
$xpath = new DOMXPath($dom);    
$script = $xpath->query ('//script[contains(text(),"sources:")]')->item (0)->nodeValue;

$json = end(explode( 'sources:', $script));
$json = explode ( ']', $json)[0].']';

echo $json 

希望有帮助

这篇关于从脚本内部获取数据,并使用php将其传递给纯文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆