如何将文本从网站存储到本地文件?
因此,基本上脚本需要执行以下操作:
-
转到这个网站(假网站)
http://website/webtv/secure?url=http://streamserver.net/channel/channel.m3u8**&TIMESTAMP**
其中CCD_ 2可以是使其唯一的时间戳。
站点将响应:
{
"url":"http://streamserver.net/channel/channel.m3u8?st=8frnWMzvuN209i-JaQ1iXA'u0026e=1451001462",
"alternateUrl":"",
"Ip":"IPADRESS"
}
- 获取url并按如下方式转换文本:
http://streamserver.net/channel/channel.m3u8?st=8frnWMzvuN209i-JaQ1iXA'u0026e=1451001462
必须是:
http://streamserver.net/channel/channel.m3u8?st=8frnWMzvuN209i-JaQ1iXA&e=1451001462
因此'u0026e
被&
取代
并将此文本存储在本地m3u8文件中。
我正在寻找一个脚本,php或任何其他代码都是受欢迎的,可以执行这一点。感谢您的帮助。
我尝试了一个小脚本来显示内容,但后来出现了错误:Failed to open stream: HTTP request Failed!
php似乎试图将其作为流而不是网站来打开。它应该将其视为一个站点,因为只有这样才会发送响应。
<?php
$url = 'http://website/webtv/secure?url=http://streamserver.net/channel/channel.m3u8&1';
$output = file_get_contents($url);
echo $output;
?>
这不是一个教程网站,所以我不会向您提供更多详细信息。您可以尝试以下代码:
<?php
$json_url = "http://linktoyour.site"; //change the url to your needs
$data = file_get_contents($json_url); //Get the content from url
$json = json_decode($data, true); //Decodes string to JSON Object
$data_to_save=$json["url"]; //Change url to whatever key you want value of
$file = 'm3u8.txt'; //Change File name to your desire
file_put_contents($file, $data_to_save); //Writes to File
?>
我认为您的PHP配置有问题。
就像allow_url_fopen
被拒绝一样。
查看更多http://php.net/manual/en/filesystem.configuration.php#ini.allow-打开的url