21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
$url="http://m.youku.com/wap/";
//$reg1="/^<a\s*href=\"(.*?)version=2\">$/i";
$reg1="/<a\s*href=\"(.*?)version=2\"(.*?)>(.*?)<\/a>/i";//获取视频链接
$reg2="/<img([^>]*)\s*class=\"imgdetail\"\s*src=('|\")([^'\"]+)('|\")/i";
$reg3="<a\s*href=\"(.*?)&format=3gphd\"\s*id=\"click_play\"\s*>";
$reg4= "/<p\s*class=\"videotitle\".*?>.*?<\/p>/i";//获取视频标题
$content=file_get_contents($url);
preg_match_all($reg1, $content,$matches);
$video=$matches[0];//首页视频的链接
$resultArray=array();//装载所有数据的数组
//$subArray=array();//子数组
foreach ($video as $key)
{
//处理url,得到视频的点击网址
$position=strpos($key, "href");
$substring=substr($key, $position+11);
$pos=strpos($substring, ">");
$link=substr($substring, 0,$pos-1);
$nextUrl=$url.$link;
$nextContent=file_get_contents($nextUrl);
//获取视频图片
preg_match_all($reg2, $nextContent,$img);
$img_arr=$img[0];
foreach ($img_arr as $arr)
{
$position=strpos($arr, "src");
$sub=substr($arr, $position+5);
$last=substr($sub, 0,$pos);
}
//获取视频高清点播地址
preg_match_all($reg3, $nextContent,$vids);
$video_arr=$vids[0];
$vid=$video_arr[0];
$position=strpos($vid, "href");
$v_string=substr($vid, $position+11);
$pos=strpos($v_string, "\"");
$add=substr($v_string, 0,$pos);
$video_url=$url.$add;
//获取视频的标题
preg_match_all($reg4, $nextContent,$match);
$title=$match[0];
$r=serialize($title);
$position=mb_strpos($r, "</p>");
$sub=substr($r, 0,$position);
$pos=mb_strrpos($sub, ">");
$til=substr($sub, $pos+1);
$subArray=array('image'=>$last,'video'=>$video_url,'title'=>$til);
array_push($resultArray, $subArray);
}
$resultJson=json_encode($resultArray);
file_put_contents('web.txt', print_r($resultJson,true));
以上就是全部代码了..