Python 批量爬取快手点赞视频

Python 批量爬取快手点赞视频

枫
2023-08-20 / 1 评论 / 106 阅读 / 耗时 173ms / 正在检测是否收录...

前言

  好久没有分享爬虫了,随便分享一个之前写的吧,也没看见有人发布这种爬虫,代码也很简单,这个只能批量爬取 自己点赞视频
嗯嗯...是需要抓取cookie的,就是快手喜欢列表cookie,直接看截图:
lljfj0sj.png

抓包

按F12进入开发人员就可以抓了,记得刷新页面才会出现数据包

lljfn53v.png

说明

  模块自己导入,视频默认保存到D:/video/文件夹,可以自己更改
下面代码自带了cookie,需要更换自己抓包

效果

lljftzgy.png
lljfwccu.png

代码

import requests
import re
import os

cookie ='kpf=PC_WEB; clientid=3; did=web_36aa4b497d25f5a44d48448da60afe50; didv=1687578212131; clientid=3; kpf=PC_WEB; kpn=KUAISHOU_VISION; _did=web_244010593DBE3F9B; ksliveShowClipTip=true; userId=3561544837; kpn=KUAISHOU_VISION; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqAB7j4FNJ3gbkzArjNtSCbdWOMoNmx1qbzusHDTZFf8CLiaBK0j0p7Sy5980HE9Q6WZ1LIU2oMY6zpVG0ETh8k6WOwYNPPKtBNmaPhN92KIHFPL6EPhpd7YKqcbeCopAZVjDsVBohAyZT9oAAtnvlHO4YpC2kitedh_ohGIblSJnrrAtdOvWc1xoEi-RjY0ms0ZD73nxvS3hmz1gJx_Qc7bChoStEyT9S95saEmiR8Dg-bb1DKRIiAId7DYCn2lhOUlYHyKsUDE-ZpLEcSd42tmMjdhGFiBRSgFMAE; kuaishou.server.web_ph=cd2589031aefc1a54981a4d60e57e7033071'
## 这里填你自己的cookie值,自己抓包吧
if not os.path.exists('D:/video/'):
    os.mkdir(('D:/video/'))
## 这里可修改保存地址
def get_next(pcursor):

    json = {
        'operationName': "visionProfileLikePhotoList",
        'query': "fragment photoContent on PhotoEntity {\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  __typename\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    __typename\n  }\n  canAddComment\n  llsid\n  status\n  currentPcursor\n  tags {\n    type\n    name\n    __typename\n  }\n  __typename\n}\n\nquery visionProfileLikePhotoList($pcursor: String, $page: String, $webPageArea: String) {\n  visionProfileLikePhotoList(pcursor: $pcursor, page: $page, webPageArea: $webPageArea) {\n    result\n    llsid\n    webPageArea\n    feeds {\n      ...feedContent\n      __typename\n    }\n    hostName\n    pcursor\n    __typename\n  }\n}\n",
        'variables': {"userId": 'id',
                      "pcursor": pcursor,
                      "page": "profile"""}

    }
    headers = {
        'Cookie': cookie,
        'Host': "www.kuaishou.com",
        'Origin': "https://www.kuaishou.com",
        'Referer': f"https://www.kuaishou.com/profile/{id}",
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.68",

    }


    url = 'https://www.kuaishou.com/graphql'

    response = requests.post(url=url, headers=headers, json=json)

    json_data = response.json()


    feeds = json_data['data']['visionProfileLikePhotoList']['feeds']
    pcursor = json_data['data']['visionProfileLikePhotoList']['pcursor']
    len_num = len(feeds)
    for feed in range(0, len_num):

        photoUrl = feeds[feed]['photo']['photoUrl']
        originCaption = feeds[feed]['photo']['originCaption']
        originCaption = re.sub('[\\/:*?<>|\\n#@)\》\."\《(\r]', '', originCaption)
        print(originCaption, photoUrl)
        with open(f'D:/video/{originCaption}''.mp4',mode='wb')as f:
            video = requests.get(photoUrl).content
            f.write(video)


    if pcursor=='no_more':
        return ''
    get_next(pcursor)


get_next("")


1

海报

正在生成.....

评论 (1)

取消
  1. 头像
    Echo
    ·Windows X64 · QQ Browser
    广东省东莞市 移动 广东省 沙发

    喜欢这篇文章,作者666,文章真棒!

    Android 13   手机QQ  回复 删除 垃圾