快手无水印下载(python小爬虫)

代码写的比较渣,大家请见谅。。。

把快手作者全部视频都下载到本地,无水印的。

拿这个作者做演示:https://www.kuaishou.com/profile/3xa5t6uapbsy9ys

打开链接,一直往下拉,拉到页面最底下。

复制好数据,保存到一个txt文本,文件名字比如为:曹爷们儿.txt

按照如下步骤操作:

再把你的cookie弄下来,比如:

把cookie粘贴到代码的这个位置:

然后就可以启动python脚本,成功后是这样的:

 

完整代码:

#coding=utf-8


import requests
import json
import os
import time

headers = {
    'content-type': 'application/json',
    'Cookie': '把你的Cookie粘贴到这里',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'
}


f = open('曹爷们儿.txt',mode='r',encoding='utf-8')
for line in f:
    if 'clientCacheKey=' in line:
        clientCacheKey1 = line.replace('</div></div></div>','</div></div></div>\n')

        with open('@temp.txt', mode='w', encoding='utf-8') as f:
            f.write(clientCacheKey1 + '\n')
            f.close()
            with open('@temp.txt', mode='r', encoding='utf-8') as f:
                for line in f:
                    try:
                        clientCacheKey2 = line.split('clientCacheKey=')[1].split('.jpg&amp;di=')[0].replace('\n', '').split('_')[0].replace('\n','')
                    except:
                        continue

                    videourl = 'https://www.kuaishou.com/short-video/' + clientCacheKey2

                    data = {
                        "operationName": "visionVideoDetail",
                        "variables": {
                            "photoId": clientCacheKey2,
                            "page": "detail",
                        },
                        "query": "query visionVideoDetail($photoId: String, $type: String, $page: String, $webPageArea: String) {\n  visionVideoDetail(photoId: $photoId, type: $type, page: $page, webPageArea: $webPageArea) {\n    status\n    type\n    author {\n      id\n      name\n      following\n      headerUrl\n      __typename\n    }\n    photo {\n      id\n      duration\n      caption\n      likeCount\n      realLikeCount\n      coverUrl\n      photoUrl\n      liked\n      timestamp\n      expTag\n      llsid\n      viewCount\n      videoRatio\n      stereoType\n      croppedPhotoUrl\n      manifest {\n        mediaType\n        businessType\n        version\n        adaptationSet {\n          id\n          duration\n          representation {\n            id\n            defaultSelect\n            backupUrl\n            codecs\n            url\n            height\n            width\n            avgBitrate\n            maxBitrate\n            m3u8Slice\n            qualityType\n            qualityLabel\n            frameRate\n            featureP2sp\n            hidden\n            disableAdaptive\n            __typename\n          }\n          __typename\n        }\n        __typename\n      }\n      __typename\n    }\n    tags {\n      type\n      name\n      __typename\n    }\n    commentLimit {\n      canAddComment\n      __typename\n    }\n    llsid\n    danmakuSwitch\n    __typename\n  }\n}\n"
                    }


                    data = json.dumps(data)
                    response = requests.post('https://www.kuaishou.com/graphql', headers=headers,data=data)
                    response.encoding = 'zh-CN'

                    json_data = response.json()
                    try:
                        data_title = str(json_data['data']['visionVideoDetail']['photo']['caption']).replace("r'[\/\\\:\*\?\"\<\>\|]'",'')
                        data_url = json_data['data']['visionVideoDetail']['photo']['photoUrl']
                        name = json_data['data']['visionVideoDetail']['author']['name']
                    except:
                        continue

                    url = data_url.split('kwaicdn.com/upic/')[1]
                    year = url.split('/')[0]
                    mouth = url.split('/')[1]
                    date = url.split('/')[2]
                    urldate = year + mouth + date

                    video_content = requests.get(url=data_url, headers=headers).content
                    filename = name + '\\'
                    if not os.path.exists(filename):
                        os.mkdir(filename)
                    try:
                        with open(filename + urldate + '_' + data_title + '.mp4',mode='wb') as f:
                            f.write(video_content)
                            print('成功爬取:\n',videourl,'\n',data_title,'\n\n')
                            time.sleep(1)

                    except:
                        continue

print('爬取完成……')

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值