<?php /** * 抖音短视频去水印 * 1、使用爬虫技术分析、php我们用的querylist * 2、在你的框架里面引入 composer jaeger/querylist:"*" * 3、分析页面,使用GuzzleHttp请求分析 (GuzzleHttp在querylist 版本4会依赖GuzzleHttp) * 4、下面我用的是TP5框架(fastadmin) * 5、调用方法:http://127.0.0.1/index/Douyin/index/?shareurl=https://v.douyin.com/poRHbN/ */ namespace app\index\controller; use QL\QueryList; use GuzzleHttp\Client; use app\common\controller\Frontend; use think\Request; class Douyin extends Frontend { protected $shareurl = ''; public function __construct() { $this->shareurl = Request::instance()->param("shareurl/s") ?: 'https://v.douyin.com/poRHbN/'; } public function index(){ $data = ['code'=>0,'msg'=>'获取成功']; $url = $this->shareurl; $str="/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/"; if (!preg_match($str,$url)){ return json(['code'=>10001,'msg'=>'url无效']); } $headers = [ 'Connection' => 'keep-alive', 'Host' => 'aweme.snssdk.com', 'User-Agent'=>'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1' ]; $client = new Client(['headers'=>$headers]); //允许重定向获取html $res = $client->request('GET', $url,['allow_redirects' => true]); $html = (string)$res->getBody(); $Query = QueryList::getInstance(); $video_src = $Query->html($html)->find('video')->src; //爬虫视频地址 $video_src = str_replace("playwm","play",$video_src); //获取url地址之后不能让他重定向 $res = $client->request('GET', $video_src,['allow_redirects' => false]); $data['video_src']= stripslashes($res->getHeaderLine('location')); //视频封面 $video_cover = $Query->html($html)->find('.video-poster')->style; $video_cover = str_replace("background-image:url(","",$video_cover); $data['video_cover'] = stripslashes(trim($video_cover,')')); $video_title = $Query->html($html)->find('.user-title')->text(); $title = explode('@',$video_title); for ($i=0;$i<count($title);$i++){ $video_title = str_replace('@'.$title[$i],"",$video_title); } $title = explode('#',$video_title); for ($i=0;$i<count($title);$i++){ $video_title = str_replace('#'.$title[$i],"",$video_title); } $video_title = str_replace("抖音","",$video_title); $data['video_title'] = stripslashes(trim($video_title)); return json($data); } }
无论从事什么行业,只要做好两件事就够了,一个是你的专业、一个是你的人品,专业决定了你的存在,人品决定了你的人脉,剩下的就是坚持,用善良專業和真诚赢取更多的信任。