找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 16903|回复: 271

[iptv信源 资源分享或寻求] PHP笔记一:获取网页源码或接口数据的不同方法

 火... [复制链接]
发表于 2022-7-28 13:25 | 显示全部楼层 |阅读模式
收集并整理了通过php的操作获取网页源码或接口数据的不同方法:

1. 通过file()函数
源码实例:迅雷美女直播;测试:http://mmitv.top/test/xunlei.php
<?php
$lines = file('https://live.xunlei.com');//file() 函数把整个文件读入一个数组中。
foreach ($lines as $line_num => $line) {
preg_match_all('/"stream_flv_pull_https":"(.*?)"/',$line,$m3u8);
if($m3u8[0]){break;}
}
$playurl=str_replace('\u002F','/',$m3u8[1][mt_rand(0,count($m3u8[1])-1)]);
//print_r($playurl);
header('location:'. $playurl);
?>
2. 通过file_get_contents()+stream_context_create函数
源码实例:成都电视1台;测试:http://mmitv.top/other/cdtv.php?id=cdtv1   http://mmitv.top/other/cdtv.php?ids=1
<?php
$url='https://www.cditv.cn/api.php?op=live&catid=2762&id=1610&videotype=m3u8&fluency=sd&type=playTv&startTime=&password=';
$headers=stream_context_create(['http'=>['header'=>['Referer: https://www.cditv.cn/']]]);//创建请求方式和头信息
$playurl=file_get_contents($url,false,$headers);
//print_r($playurl);
header('location:'. $playurl);
?>
3. 通过fopen()和fread()函数
源码实例:CC美女直播;测试:http://mmitv.top/test/cc.php?id=top
<?php
$handle = fopen('https://api.cc.163.com/v1/wapcc/liveinfo?gametype=65005&page='.mt_rand(1,5), 'r');    // 以只读方式打开文件并将指针指向文件头,资源类型
$contents = '';
while (!feof($handle)){    // 判断文件指针是否到了文件的末尾
$contents .= fread($handle, 1024);    // 每次读取1024个字节的数据
}
fclose($handle);    // 关闭文件
$json = json_decode($contents);
$id=$json->data->live_list[mt_rand(0,11)]->ccid;
$playurl = 'http://cgi.v.cc.163.com/redirect/video/'.$id.'.flv';
//echo $playurl;
header('location:'. $playurl);
?>
4. 通过php的curl扩展库;常用。
源码实例:KK美女直播;实例二测试:http://mmitv.top/test/kk.php
实例一:
<?php
$ch = curl_init();// 创建一个curl会话资源
curl_setopt($ch, CURLOPT_URL, "https://www.kktv5.com");// 设置curl相应的选项
curl_setopt($ch, CURLOPT_HEADER, 0);//不输出请求信息。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//结果返回,不自动输出任何内容。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);// 执行curl
curl_close($ch);// 关闭curl会话
preg_match_all('/target="actor_(\d.*?)".*?alt="(.*?)"/',$data,$str1);
preg_match_all('/a href="\/(\d.*?)" class="actor video_cover" target="_blank" title="(.*?)"/',$data,$str2);
$id=$str1[1]+$str2[1];
$playurl='https://pull.kktv8.com/livekktv/'.$id[mt_rand(0,count($id)-1)].'.flv';
//print_r($playurl);
header('location:'. $playurl);
?>
备注:实例一在我的服务器上curl不出数据。不知是网络限制、地域限制、还是服务器问题。还请坛友测试解惑...
实例二:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sapi.kktv1.com/meShow/entrance?parameter={"c":"8001","cid":"810","pageIndex":1,"countPerPage":10,"FuncTag":51070104,"userId":0,"platform":1,"a":1}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
curl_close($ch);
preg_match_all('/"liveStream":"(.*?)"/',$data,$str);
$playurl=$str[1][mt_rand(0,count($str[1])-1)];
//print_r($playurl);
header('location:'. $playurl);
?>

我的恩山、我的无线 The best wifi forum is right here.
发表于 2022-7-28 13:29 | 显示全部楼层
谢谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 13:32 来自手机 | 显示全部楼层
谢谢分享,正是所求。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 13:33 | 显示全部楼层
看看是啥
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 13:41 | 显示全部楼层
来来来看看
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 13:47 来自手机 | 显示全部楼层
口数据的不同
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 13:55 | 显示全部楼层
这有什么用?求解答
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:05 | 显示全部楼层
谢谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:13 | 显示全部楼层
感谢分享,学习ing
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:20 来自手机 | 显示全部楼层
感谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:28 | 显示全部楼层
技术贴技术贴技术贴
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:34 | 显示全部楼层
看看是啥玩意
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:36 | 显示全部楼层
难得好帖子
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:47 | 显示全部楼层
PHP笔记一:获取网页源码或接口数据的不同方法
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-28 14:47 | 显示全部楼层
谢谢分享!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-19 19:48

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表