文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

PHP抖音最新视频提取代码

2023-09-27 05:33

关注

PHP抖音视频最新提取代码

研究了很多天,发现直接调用接口感觉不太行,所以只能采集HTML页面内容了。
下面直接附上代码吧
需要安装插件库

use GuzzleHttp\Client;

这里大家自行百度查找这个插件库吧
下面是代码

public function Video()    {        // 视频分享链接        $url = 'https://v.douyin.com/UYwNRAK/';        // 发送 GET 请求获取视频的 HTML 页面        $client = new Client([            'verify' => false,            'allow_redirects' => [                'max' => 0,            ],        ]);        $response = $client->get($url);        $html = $response->getBody()->getContents();        // 从 HTML 页面中提取视频的真实地址        $pattern = '/video\/(.*?)\//';        preg_match($pattern, $html, $matches);        //拼接PC版地址        $pcUrl = "https://www.douyin.com/video/";        if (isset($matches[1])) {            $video_url = $pcUrl.$matches[1];        } else {            return '未找到视频地址';        }        // 提取真实视频        $headers = [            'cookie' => 'douyin.com; n_mh=XoDi_bSkJjNjXuJ1wDYlv4ldwjaX643aMZ3ct-LUBuY; passport_assist_user=CkHOiAxW7DPVkzSUwHFXlPOWPTndBZisSIHT4Y7YZnIyrj79kbtwg0qrp03a0_TrcKZauQqaYJJwkD-UyvDBY3gAORpICjxaND7jRScgUDoHf5ZAOjrtbqcIyYpgFElDUD0QgWw7WWi8DsU5XVmAddI-uaQQZsqaeAf0pZrOM9JIBJQQnMKqDRiJr9ZUIgEDS9nfMg%3D%3D; sso_uid_tt=199257f0818bf1ca098f6e7b23ff5bbb; sso_uid_tt_ss=199257f0818bf1ca098f6e7b23ff5bbb; toutiao_sso_user=d50cf18a6bc2eef4710c6d2bf2fe8eca; toutiao_sso_user_ss=d50cf18a6bc2eef4710c6d2bf2fe8eca; uid_tt=6437b6f4afa709a189575a49d99a28ee; uid_tt_ss=6437b6f4afa709a189575a49d99a28ee; sid_tt=b711fa12a4c693159784ced8fec69206; sessionid=b711fa12a4c693159784ced8fec69206; sessionid_ss=b711fa12a4c693159784ced8fec69206; store-region-src=uid; ttwid=1%7CquN0IBK7KSK-fmohDybqYHtKjvLepKzHlfZySXOlMl0%7C1678373545%7C2fbb952b99105dc8b7ccad56d653b4840fcb73f90a8f187cbedca8afbcfa357f; odin_tt=eb063b5e9c7cb092c048b9fcf36a7f91c8f38d9f72edafe90a60e686a2ae9670710da4907098c99287979236d258e5f0; __live_version__=%221.1.0.7804%22; s_v_web_id=verify_lhkesk8n_oJ4jNKCG_PS9j_4ozB_8I30_ObnqdZ85vyqE; LOGIN_STATUS=1; passport_csrf_token=1fe8a546129830c60049640293fbbf33; passport_csrf_token_default=1fe8a546129830c60049640293fbbf33; sid_ucp_sso_v1=1.0.0-KGJmM2M2YjA3OGZhMTE5MWEyMjJhNmY0ZDJjM2IyMTMzMjM0YjZmZGQKHwj3g5Hti_TfAxDFpviiBhjvMSAMMOO2r_gFOAZA9AcaAmxmIiBkNTBjZjE4YTZiYzJlZWY0NzEwYzZkMmJmMmZlOGVjYQ; ssid_ucp_sso_v1=1.0.0-KGJmM2M2YjA3OGZhMTE5MWEyMjJhNmY0ZDJjM2IyMTMzMjM0YjZmZGQKHwj3g5Hti_TfAxDFpviiBhjvMSAMMOO2r_gFOAZA9AcaAmxmIiBkNTBjZjE4YTZiYzJlZWY0NzEwYzZkMmJmMmZlOGVjYQ; sid_ucp_v1=1.0.0-KDY2OGIyZTYyNGQ5YjUzZTViMDA3YzhjZDEwYzg4MTc0YjI3NjExZGQKGwj3g5Hti_TfAxDGpviiBhjvMSAMOAZA9AdIBBoCbHEiIGI3MTFmYTEyYTRjNjkzMTU5Nzg0Y2VkOGZlYzY5MjA2; ssid_ucp_v1=1.0.0-KDY2OGIyZTYyNGQ5YjUzZTViMDA3YzhjZDEwYzg4MTc0YjI3NjExZGQKGwj3g5Hti_TfAxDGpviiBhjvMSAMOAZA9AdIBBoCbHEiIGI3MTFmYTEyYTRjNjkzMTU5Nzg0Y2VkOGZlYzY5MjA2; sid_guard=b711fa12a4c693159784ced8fec69206%7C1683886918%7C5184001%7CTue%2C+11-Jul-2023+10%3A21%3A59+GMT; download_guide=%223%2F20230512%22; publish_badge_show_info=%221%2C0%2C0%2C1683920285202%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1684527233147%2C%22type%22%3A1%7D; pwa2=%223%7C1%22; strategyABtestKey=%221684003641.406%22; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtY2xpZW50LWNlcnQiOiItLS0tLUJFR0lOIENFUlRJRklDQVRFLS0tLS1cbk1JSUNGVENDQWJ1Z0F3SUJBZ0lWQU12ak5kdWwvMGJzL3UycGJCZEg5L05CV2t2NU1Bb0dDQ3FHU000OUJBTUNcbk1ERXhDekFKQmdOVkJBWVRBa05PTVNJd0lBWURWUVFEREJsMGFXTnJaWFJmWjNWaGNtUmZZMkZmWldOa2MyRmZcbk1qVTJNQjRYRFRJek1ESXlPREV4TURBeE1Gb1hEVE16TURJeU9ERTVNREF4TUZvd0p6RUxNQWtHQTFVRUJoTUNcblEwNHhHREFXQmdOVkJBTU1EMkprWDNScFkydGxkRjluZFdGeVpEQlpNQk1HQnlxR1NNNDlBZ0VHQ0NxR1NNNDlcbkF3RUhBMElBQk5zZjZzUmJyUmN6WjZERXVkZ2FVVTZvaGtzcXRNRXdwUVByRFhnelJYK1ZaQVBvR0djRFZJK2NcbkZWVmg1OTMzczJ0UGxMclVOaTNuaTdWQXBFdHVwaUdqZ2Jrd2diWXdEZ1lEVlIwUEFRSC9CQVFEQWdXZ01ERUdcbkExVWRKUVFxTUNnR0NDc0dBUVVGQndNQkJnZ3JCZ0VGQlFjREFnWUlLd1lCQlFVSEF3TUdDQ3NHQVFVRkJ3TUVcbk1Da0dBMVVkRGdRaUJDQXQ1a0QySFE3cU5Vcmc0ckp1aGtveXExV2RseGFKRWlXb1VqOFFqall1WFRBckJnTlZcbkhTTUVKREFpZ0NBeXBXZnFqbVJJRW8zTVRrMUFlM01VbTBkdFUzcWswWURYZVpTWGV5SkhnekFaQmdOVkhSRUVcbkVqQVFnZzUzZDNjdVpHOTFlV2x1TG1OdmJUQUtCZ2dxaGtqT1BRUURBZ05JQURCRkFpQWxqbGIrcmxqSUJQaWhcbnNIR1JlQ0kwUTRvM0huei9TY09rK2VqTFU5N3RHd0loQU8zSHdNVk5TemJyeHg3ZWg1TGYyaWlScHdvMmlKZzZcblZ2Wm1LMzdSVlI1VFxuLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLVxuIn0=; __ac_nonce=0645ff00000f75f4788f4; __ac_signature=_02B4Z6wo00f01FQurqgAAIDBg-iD0aqOo0xUD6oAAHFbCPW7..bnqd4GeYfz0C-Z2X8xGhJJ-bYcCD7KPAV166YWo85cXdcB5Gtp090nR0XZytb6ffusk844nWAwp.wqHPPi6tfl5UtEgSpW1b; passport_fe_beating_status=true; store-region=jp; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAye4-wu2qZKx-KO0GROKB2FmKyf49fVMxKYUDXvZwEwfdsWY27ilG_WzKvbjeom5e%2F1684080000000%2F0%2F0%2F1684010722905%22; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAye4-wu2qZKx-KO0GROKB2FmKyf49fVMxKYUDXvZwEwfdsWY27ilG_WzKvbjeom5e%2F1684080000000%2F0%2F0%2F1684011322906%22; msToken=KhEOm2c2mvPPMtcWiszPHquy5A4Bj3hVWfLfWpq-qeVO8wUjMiyvy2UFRr5oJmxpuuVAeozA55F-GGxWZ0AW19XFA9xvvuSHKr27JfKsQb_wbXtKjkQEHZRnGZ0Ldm2Y; home_can_add_dy_2_desktop=%221%22; msToken=4JHnCUN-upd5zjVZH-TEKkr-xKHe0BzJs6Dar9NP1hhvpkyu8PuSP4gtdtfG844zvnieR_GfRbyd2BvKE6IuS0gNjP73XxN8SgwB_qEPOTLFk6XTmNZJ93rkpLk6E_oy; tt_scid=My71Yv1CSaW9.ELn18.o-CxCGsLxvsM.2DhK4tMDRqoIn0e0LVJwWbZ4.cLTEZh86dd5',            'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',        ];        $response = $client->get($video_url,[            'headers' => $headers,        ]);        $video_data = $response->getBody()->getContents();        $decodedUrl = urldecode($video_data);        $pattern = '/(.*?)<\/script>/';        if (preg_match($pattern, $decodedUrl,$matches)) {            $array = json_decode($matches[1], true);            //视频描述            $Arr = [                'desc' => $array[46]['aweme']['detail']['desc'],                'videoUrl' => "https:".$array[46]['aweme']['detail']['video']['playAddr'][0]['src'],                'videoCover' => "https:".$array[46]['aweme']['detail']['video']['cover'],                'videoMusic' => $array[46]['aweme']['detail']['music']['playUrl']['uri']            ];            return json(['code' => 200, 'data' => $Arr]);        } else {            echo '匹配失败!';        }    }

觉得有用的老板可以给个打赏哈
在这里插入图片描述

来源地址:https://blog.csdn.net/qq_36203073/article/details/130746406

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯