最近闲来无事捣鼓影视cms,突然发现一些采集网站,于是乎想自己做一个视频网站玩玩
用PHP爬取某影视网的影视资源,跟现在网上流行的VIP影视网站和软件都是一样的地址来源
废话不多说,除了分享代码之外,我也把自己的接口分享出来。接口适应手机版,微信打开要点击访问原网站(http://llllll.ga)。
留下的接口:
- 查询影片:http://llllll.ga/inc/all.php?name=参数
- 播放列表:http://llllll.ga/inc/one.php?id=/?id=参数
先用软件分析出来它是用POST传的'wd=参数',然后传入参数进行爬取,根据传入的参数获取到影视的名字和地址,代码:
[PHP] 纯文本查看 复制代码 <?php
header("Content-type: text/html; charset=utf-8");
$name = 'wd='.$_GET['name'];
$html = (string)request_by_curl('http://yongjiuzy.net/index.php?m=vod-search',$name);
$a = '/<td class=\".*\"><a href=\"(.*)\" .*>(.*)<font color=\".*\">/';
preg_match_all($a,$html,$m);
foreach ($m[2] as $value) {
$text[] = $value;
}
foreach ($m[1] as $value) {
$href[] = $value;
}
$all = array('name' =>$text ,'href' =>$href );
$all_json = json_encode($all);
echo $all_json;
function request_by_curl($remote_server, $post_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $remote_server);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "ChinaLBT");
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
然后再把地址传入,获取播放列表,代码:
[PHP] 纯文本查看 复制代码 <?php
header("Content-type: text/html; charset=utf-8");
$id = $_GET['id'];
$url = 'http://yongjiuzy.net'.$id;
$html = file_get_contents($url);
$all_hrml = substr($html,strpos($html,'<!--火车头地址开始')+25 );
$over = strpos($all_hrml,'火车头地址结束-->');
$over_html = substr($all_hrml,0,$over);
$a = '#<li>(.*?)\$(.*?)<\/li>#';
preg_match_all($a,$all_hrml,$m);
foreach ($m[1] as $value) {
$text[] = $value;
}
foreach ($m[2] as $value) {
$href[] = $value;
}
$all = array('name' =>$text ,'href' =>$href );
$all_json = json_encode($all);
echo $all_json;
function request_by_curl($remote_server, $post_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $remote_server);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "ChinaLBT");
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
代码有很多不规范之处,可能看起来有点累。 |