【爬虫】随机下载短视频工具,只要输入名称和地址

import requests
import re
import os
episodeNumber = 0
title = input("请你输入你的下载的短视频名称:")
if not os.path.exists(title):
    os.mkdir(title)
url =  input("请你输入你的短视频网址:")
tubeId = re.findall("tubeId=(.*?)&",url)[0]
while True:
    cookies = {
        'kpf': 'PC_WEB',
        'clientid': '3',
        'did': 'web_54c72039dc16f496133eef1f656266c1',
        'kpn': 'KUAISHOU_VISION',
    }

    headers = {
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive',
        # 'Cookie': 'kpf=PC_WEB; clientid=3; did=web_54c72039dc16f496133eef1f656266c1; kpn=KUAISHOU_VISION',
        'Origin': 'https://www.kuaishou.com',
        'Pragma': 'no-cache',
        'Referer': 'https://www.kuaishou.com/short-video/3x7aqq3isbm7x6a?streamSource=theater&currentPcursor=1&tubeId=5xg8rrxzucwc4nk&fromPage=theater&fromChannal=0',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
        'accept': '*/*',
        'content-type': 'application/json',
        'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
    }

    json_data = {
        'operationName': 'visionTubeEpisodeQuery',
        'variables': {
            'tubeId': tubeId,
            'episodeNumber': episodeNumber,
            'page': 'theater',
            'channelId': 0,
        },
        'query': 'fragment photoContent on PhotoEntity {\n  __typename\n  id\n  duration\n  caption\n  originCaption\n  likeCount\n  viewCount\n  commentCount\n  realLikeCount\n  coverUrl\n  photoUrl\n  photoH265Url\n  manifest\n  manifestH265\n  videoResource\n  coverUrls {\n    url\n    __typename\n  }\n  timestamp\n  expTag\n  animatedCoverUrl\n  distance\n  videoRatio\n  liked\n  stereoType\n  profileUserTopPhoto\n  musicBlocked\n  riskTagContent\n  riskTagUrl\n}\n\nfragment recoPhotoFragment on recoPhotoEntity {\n  __typename\n  id\n  duration\n  caption\n  originCaption\n  likeCount\n  viewCount\n  commentCount\n  realLikeCount\n  coverUrl\n  photoUrl\n  photoH265Url\n  manifest\n  manifestH265\n  videoResource\n  coverUrls {\n    url\n    __typename\n  }\n  timestamp\n  expTag\n  animatedCoverUrl\n  distance\n  videoRatio\n  liked\n  stereoType\n  profileUserTopPhoto\n  musicBlocked\n  riskTagContent\n  riskTagUrl\n}\n\nfragment feedContent on Feed {\n  type\n  author {\n    id\n    name\n    headerUrl\n    following\n    headerUrls {\n      url\n      __typename\n    }\n    __typename\n  }\n  photo {\n    ...photoContent\n    ...recoPhotoFragment\n    __typename\n  }\n  canAddComment\n  llsid\n  status\n  currentPcursor\n  tags {\n    type\n    name\n    __typename\n  }\n  __typename\n}\n\nquery visionTubeEpisodeQuery($tubeId: String, $episodeNumber: Int, $page: String, $channelId: Int, $webPageArea: String) {\n  visionTubeEpisode(tubeId: $tubeId, episodeNumber: $episodeNumber, page: $page, channelId: $channelId, webPageArea: $webPageArea) {\n    ...feedContent\n    result\n    status\n    __typename\n  }\n}\n',
    }

    response = requests.post('https://www.kuaishou.com/graphql', cookies=cookies, headers=headers, json=json_data)

    # https://www.kuaishou.com/short-video/3xxhitk2szntnhe?streamSource=theater&tubeId=5xg8rrxzucwc4nk&fromPage=theater&fromChannal=0

    down_url = re.findall('"photoUrl":"(.*?)","',response.text)

    res = requests.get(down_url[0],headers=headers)
    open(f"{title}/第{episodeNumber+1}集.mp4","wb").write(res.content)
    episodeNumber+=1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

青龙摄影

你的鼓励是我创作的动力,支持下

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值