欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Python實(shí)現(xiàn)批量保存視頻到本地

 更新時(shí)間:2022年05月27日 08:38:45   作者:嗨學(xué)編程  
我們刷視頻時(shí)常常會(huì)想把精彩的視頻保存到本地,如果少數(shù)的還行,如果有很多的話一個(gè)個(gè)保存太麻煩了。本文教你如何用Python實(shí)現(xiàn)視頻批量保存到本地,需要的可以參考一下

序言

是我太久沒發(fā)了嗎?昨天沒人看,那么今天來點(diǎn)特別的~

不僅把好看的視頻全部pa下來,咱們還要實(shí)現(xiàn)自動(dòng)評(píng)論、點(diǎn)贊、關(guān)注三連~

寶,你也可以順手給我個(gè)三連嗎?給你個(gè)摸摸大~

開始代碼

獲取視頻的代碼

import requests     # 發(fā)送請(qǐng)求 第三方模塊(第三方應(yīng)用 pip)
import re


# 偽裝
# 1. 選中要替換的代碼
# 2. ctrl + R
# 3. 第一個(gè)框(.*?): (.*)
# 4. 在第二個(gè)框里面輸入 '$1': '$2',
# 5. 點(diǎn)擊全部替換(* 點(diǎn)亮 * 號(hào))
headers = {
    'content-type': 'application/json',
    'Cookie': 'kpf=PC_WEB; kpn=KUAISHOU_VISION; clientid=3; did=web_ea128125517a46bd491ae9ccb255e242; client_key=65890b29; didv=1646739254078; userId=270932146; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABctRgGaXi5efEBpnbdtJMp3nnnXqENRWBoFQABtOr1ZFUNAjEo5NTZ4F0leSypsSFE4_-FGTnBqKEYh8Wcrszm3FGF03559Z9bFQCX_8ew_kLKPWVB9ZRlWQgISoG4-XZXIOqiBgkQKsPbpYKiA3X4_0rMDbo9-c0nWXeOoThekj8W3u7_yfI4fUY3h5WgTEDYT0yrXkZmhWlFV_jpVxDrBoSzFZBnBL4suA5hQVn0dPKLsMxIiCo1i0bY9V6-OVEk7yMnH86RNliTZACHvLPjL9FTHHQOigFMAE; kuaishou.server.web_ph=09735672944cbf9e53431bf3e0514a0d058b',
    'Host': 'www.***.com',
    'Origin': 'https://www.***.com',
    # 防盜鏈
    'Referer': 'https://www.kuaishou.com/profile/3xhv7zhkfr3rqag',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36',
}
url = 'https://www.***.com/graphql'


def get_page(pcursor):
    # 指定要誰的視頻
    data = {
        "operationName": "visionProfilePhotoList",
        "query": "query visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {\n  visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {\n    result\n    llsid\n    webPageArea\n    feeds {\n      type\n      author {\n        id\n        name\n        following\n        headerUrl\n        headerUrls {\n          cdn\n          url\n          __typename\n        }\n        __typename\n      }\n      tags {\n        type\n        name\n        __typename\n      }\n      photo {\n        id\n        duration\n        caption\n        likeCount\n        realLikeCount\n        coverUrl\n        coverUrls {\n          cdn\n          url\n          __typename\n        }\n        photoUrls {\n          cdn\n          url\n          __typename\n        }\n        photoUrl\n        liked\n        timestamp\n        expTag\n        animatedCoverUrl\n        stereoType\n        videoRatio\n        profileUserTopPhoto\n        __typename\n      }\n      canAddComment\n      currentPcursor\n      llsid\n      status\n      __typename\n    }\n    hostName\n    pcursor\n    __typename\n  }\n}\n",
        "variables": {"userId": "3x2vsxyxbbwcjta", "pcursor": pcursor, "page": "profile"}
    }
    # 1. 發(fā)送請(qǐng)求  get  post
    response = requests.post(url=url, headers=headers, json=data)
    # <Response [200]>: 請(qǐng)求成功
    # 2. 獲取數(shù)據(jù) .json() 返回字典類型數(shù)據(jù)
    # .text: 拿到的就是 文本內(nèi)容 python數(shù)據(jù)類型 字符串 > 字典類型 > 鍵值對(duì)(拼音)方式取值
    json_data = response.json()
    # 3. 解析數(shù)據(jù)
    # 新華字典 = {'A': '啊', 'B': '不', 'C': '從'}
    # 新華字典['B']  python數(shù)據(jù)容器 存儲(chǔ)數(shù)據(jù)
    # 正則
    feeds = json_data['data']['visionProfilePhotoList']['feeds']
    pcursor = json_data['data']['visionProfilePhotoList']['pcursor']
    for feed in feeds:
        photoUrl = feed['photo']['photoUrl']
        caption = feed['photo']['caption']
        # 正則替換
        # 第一個(gè)參數(shù)里面是需要替換的一些字符
        # 第二個(gè)參數(shù) 是把這些字符替換為 空
        # 第三個(gè)參數(shù) 是需要替換的變量
        # \\ : \
        # \/ : /
        caption = re.sub('[\\\/:*?"<>|\n]', '', caption)
        print(caption, photoUrl)
        # 4. 保存數(shù)據(jù)  如果你們拿到的鏈接 就是 視頻 或者 音頻 或者 圖片
        # .content: 獲取視頻(音頻 / 圖片) 二進(jìn)制數(shù)據(jù)
        video_data = requests.get(photoUrl).content
        # 視頻名稱
        # wb 以二進(jìn)制覆蓋寫入
        with open(f'video/{caption}.mp4', mode='wb') as f:
            f.write(video_data)
    # 遞歸: 2.出口
    if pcursor == "no_more":
        # 退出?
        return
    # 遞歸: 1.自己調(diào)用自己
    get_page(pcursor)

get_page("")

自動(dòng)評(píng)論

def post_comment(self, content, photoAuthorId, photoId):
    """
    :param content: 評(píng)論內(nèi)容
    :param photoAuthorId: 該作品的作者id
    :param photoId: 作品id
    :return: 有沒有成功
    """
    json = {
        'operationName': "visionAddComment",
        'query': "mutation visionAddComment($photoId: String, $photoAuthorId: String, $content: String, $replyToCommentId: ID, $replyTo: ID, $expTag: String) {  (photoId: $photoId, photoAuthorId: $photoAuthorId, content: $content, replyToCommentId: $replyToCommentId, replyTo: $replyTo, expTag: $expTag) {\n    result\n    commentId\n    content\n    timestamp\n    status\n    __typename\n  }\n}\n",
        'variables': {
            'content': content,
            'expTag': "1_a/2005158523885162817_xpcwebsearchxxnull0",
            'photoAuthorId': photoAuthorId,
            'photoId': photoId
        }
    }
    response = requests.post(url=self.url, json=json, headers=self.headers)
    json_data = response.json()
    print(json_data)
    return json_data

自動(dòng)點(diǎn)贊

def is_like(self, photoId, photoAuthorId):
    """
    :param photoId: 作品id
    :param photoAuthorId: 該作品的作者id
    :return: 有沒有成功
    """
    json = {
        'operationName': "visionVideoLike",
        'query': "mutation visionVideoLike($photoId: String, $photoAuthorId: String, $cancel: Int, $expTag: String) {\n  visionVideoLike(photoId: $photoId, photoAuthorId: $photoAuthorId, cancel: $cancel, expTag: $expTag) {\n    result\n    __typename\n  }\n}",
        'variables': {
            'cancel': 0,
            'expTag': "1_a/2005158523885162817_xpcwebsearchxxnull0",
            'photoAuthorId': photoAuthorId,
            'photoId': photoId
        }
    }
    response = requests.post(url=self.url, json=json, headers=self.headers)
    json_data = response.json()
    print(json_data)
    return json_data

自動(dòng)關(guān)注

def is_follow(self, touid):
    """

    :param touid: 用戶id
    :return:
    """
    json = {
        'operationName': "visionFollow",
        'query': "mutation visionFollow($touid: String, $ftype: Int, $followSource: Int, $expTag: String) {\n  visionFollow(touid: $touid, ftype: $ftype, followSource: $followSource, expTag: $expTag) {\n       followStatus\n    hostName\n    error_msg\n    __typename\n  }\n}\n",
        'variables': {
            'expTag': "1_a/2005158523885162817_xpcwebsearchxxnull0",
            'followSource': 3,
            'ftype': 1,
            'touid': touid
        }
    }
    response = requests.post(url=self.url, json=json, headers=self.headers)
    json_data = response.json()
    print(json_data)
    return json_data

以上就是基于Python實(shí)現(xiàn)批量保存視頻到本地的詳細(xì)內(nèi)容,更多關(guān)于Python保存視頻的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論