|
在论坛有一段时间了...学到的东西很多.易可以说水平达到中级了吧.(虽然没分享过有价值的东西..)..只是个人喜欢的还是php...所以这次分享一个内涵段子视频抓取的php源码...(本人比较擅长写机器人插件//这个源码也是用于机器人插件娱乐上面的..不知道对大家有没有用.)
- <?php
- echo '<pre>';
- $class = array(
- '1' => 'category/65',
- '2' => 'category/66',
- '3' => 'category/67',
- '4' => 'category/68'
- );
- $rand = rand(1,10);//定义随机数1-10
- $eff = strtotime( "-$rand hous" );//取现在的时间戳减去随机数的所得的时间戳(时间:时);
- $url = "http://m.neihanshequ.com/".$class[rand(1,4)]."/?is_json=1&app_name=neihanshequ_web&max_time=$eff&csrfmiddlewaretoken=9bf71ecdaf92274d2953459749357f5f";
- $cookie = 'uuid="w:8ee07e50d912446498c7d2c752d2708e"; skip_guidence=1; tt_webid=62365624471; csrftoken=9bf71ecdaf92274d2953459749357f5f';
- $data = get_curl($url,$cookie);
- $data = json_decode($data);
- $da = $data->data->data[$rand]->group;//取出一个数据保存在$da变量;
- $mp4_url = $da->mp4_url;//取出mp4播放地址;
- $share_url = $da->share_url;//取出原文地址;
- $content = $da->content;//取出视频标题;
- $category_name = $da->category_name;//取出视频分类;
- $medium_cover = $da->medium_cover->url_list[0]->url;//取出视频图片预览;
- $user_img = $da->user->avatar_url;//取出用户头像;
- $user_name = $da->user->name;//取出用户名称;
- $play_count = $da->play_count;//取出播放次数;
- echo "视频地址: ".$mp4_url.
- "<br/>原文地址: ".$share_url.
- "<br/>视频标题: ".$content.
- "<br/>视频分类: ".$category_name.
- "<br/>图片预览: ".$medium_cover.
- "<br/>用户头像: ".$user_img.
- "<br/>用户昵称: ".$user_name.
- "<br/>播放次数: ".$play_count;
- function get_curl($url,$cookie=0,$post=0,$referer=0,$header=0,$ua=0,$nobaody=0){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- $httpheader[] = "Accept:*/*";
- $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
- $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
- $httpheader[] = "Connection:close";
- curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
- if($post){
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- }
- if($header){
- curl_setopt($ch, CURLOPT_HEADER, TRUE);
- }
- if($cookie){
- curl_setopt($ch, CURLOPT_COOKIE, $cookie);
- }
- if($referer){
- if($referer==1){
- curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
- }else{
- curl_setopt($ch, CURLOPT_REFERER, $referer);
- }
- }
- if($ua){
- curl_setopt($ch, CURLOPT_USERAGENT,$ua);
- }else{
- curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Linux; Android 4.4.2; NoxW Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36');
- }
- if($nobaody){
- curl_setopt($ch, CURLOPT_NOBODY,1);
- }
- curl_setopt($ch, CURLOPT_ENCODING, "gzip");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- $ret = curl_exec($ch);
- curl_close($ch);
- return $ret;
- }
- ?>
复制代码
|
|