Python爬虫:fiddler抓取快手

2020-07-25  本文已影响0人  轻语风

类似于上一篇Fiddler抓取抖音

Fiddler脚本

if (oSession.uriContains("https://apissl.ksapisrv.com/rest/n/feed/")){
            var strBody=oSession.GetResponseBodyAsString()
            var timestamp=new Date().getTime()
            var filename = "G://software//ks" + "/" + timestamp + ".json";
            var curDate = new Date();   
            var sw : System.IO.StreamWriter;  
            if (System.IO.File.Exists(filename)){  
            sw = System.IO.File.AppendText(filename);  
                sw.Write(strBody); 
        }  
            else{  sw = System.IO.File.CreateText(filename); 
               sw.Write(strBody);
            }  
            sw.Close();
            sw.Dispose(); 
        }

注:oSession.uriContains("此处需要修改")

源码奉上

import os,json,requests
# 请求头
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36'}

videos_list = os.listdir('G:/software/ks/')  #获取文件夹内所有json包名

count = 1  #计数,用来作为视频名字

for videos in videos_list:  #循环json列表,对每个json包进行操作
    a = open('G:/software/ks/{}'.format(videos),encoding='utf-8')  #打开json包
    content = json.load(a)['feeds'] #取出json包中所有视频

    for video in content:  #循环视频列表,选取每个视频
        video_url = video['main_mv_urls'][0]['url']
        print(video_url)
        videoMp4 =  requests.get(video_url,headers=headers).content #获取视频二进制代码
        with open('G:/software/ks_video/{}.mp4'.format(count),'wb') as f: #以二进制方式写入路径,记住要先创建路径
            f.write(videoMp4)  #写入
            print('视频{}下载完成'.format(count)) #下载提示
        count += 1 #计数+1

运行结果展示

代码运行结果.png 视频文件.png
上一篇下一篇

猜你喜欢

热点阅读