当前位置: 首页>前端>正文

Python 采集 快手 实现视频批量保存

鍓嶈█

鍡ㄥ柦~澶у濂藉憖锛岃繖閲屾槸榄旂帇鍛?鉂?~!

Python 采集 快手 实现视频批量保存,第1张

鍒峰埌鐨勮棰戞€曞畠涓嬫灦锛熸垜浠潵閲囬泦淇濆瓨涓€涓嬪畠

Python 采集 快手 实现视频批量保存,第2张

鐭ヨ瘑鐐?

  • 鍔ㄦ€佹暟鎹姄鍖?/p>

  • requests鍙戦€佽姹?/p>

  • json鏁版嵁瑙f瀽

寮€鍙戠幆澧?

  • python 3.8 杩愯浠g爜

  • pycharm 2022.3 杈呭姪鏁蹭唬鐮?/p>

  • requests pip install requests

Python 采集 快手 实现视频批量保存,第3张

浠g爜灞曠ず

瀵煎叆妯″潡

import re

import requests     # 鍙戦€佽姹?

浼

headers = {
    'Cookie': 'kpf=PC_WEB; clientid=3; did=web_4bf90ac4df8aaef2d99527f1da1063fd; userId=3075864129; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqAB9tSqSgbeN3Qhc4H_V6Awn1-yfEnaceVEJQUhtxgCBBHHQl_DyWKPYDO3XIdjFQTHwSSFOPZL6FPTk7LSW1dfp7qvBSeP4ANjPT1evIoq9ODcPJyb6YgEIdsV-Dzm_Sq73yQg6jYhvuRNJGwAM_GfAfUKWiG4RDdGDpHd1uCAJd0qM2xZwqzr11JlIz3yRFeNFNfO2zINkJAktY8lUyQwuRoS9XMBYg26NCtIxdOwhbHEY-u6IiBNGgmRMQXPmCodWM1RM7oFpjHSgD61betJSR00w0VYtSgFMAE; kuaishou.server.web_ph=69e54c87baac46f523262858017c7988cf22; kpn=KUAISHOU_VISION',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'
}

璇锋眰閾炬帴

url = 'https://www.****.com/graphql'
pcursor = ""
while True:
    # 璇锋眰浣?
    json = {
        'operationName': "visionProfilePhotoList",
        'query': "fragment photoContent on PhotoEntity {\n  id\n  duration\n  caption\n  originCaption\n  likeCount\n  viewCount\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 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      ...feedContent\n      __typename\n    }\n    hostName\n    pcursor\n    __typename\n  }\n}\n",
        'variables': {'userId': "3xjfq9eesf4kxwg", 'pcursor': pcursor, 'page': "profile"}
    }
  1. 鍙戦€佽姹?/li>
    response = requests.post(url=url, headers=headers, json=json)
  1. 鑾峰彇鏁版嵁
    json_data = response.json()
  1. 瑙f瀽鏁版嵁

閿? 鍊?閫氳繃:鍓嶉潰鐨勫唴瀹?鍙?鍚庨潰鐨勫唴瀹?/p>

    feeds = json_data['data']['visionProfilePhotoList']['feeds']
    pcursor = json_data['data']['visionProfilePhotoList']['pcursor']
    for feed in feeds:
        photoUrl = feed['photo']['photoUrl']
        caption = feed['photo']['caption']
        caption = re.sub('[\\/:*?"<>|]', '', caption)
        print(caption, photoUrl)
  1. 淇濆瓨鏁版嵁
        video_data = requests.get(photoUrl).content
        with open(rf"C:\Users\Administrator\Desktop\video\{caption}.mp4", mode='wb') as f:
            f.write(video_data)
    if pcursor == "no_more":
        break

鏁堟灉灞曠ず

Python 采集 快手 实现视频批量保存,第4张
Python 采集 快手 实现视频批量保存,第5张

Python 采集 快手 实现视频批量保存,第6张
Python 采集 快手 实现视频批量保存,第7张
Python 采集 快手 实现视频批量保存,第8张

Python 采集 快手 实现视频批量保存,第9张

Python 采集 快手 实现视频批量保存,第10张
Python 采集 快手 实现视频批量保存,第11张

Python 采集 快手 实现视频批量保存,第12张

灏捐 馃挐

瑕佹垚鍔燂紝鍏堝彂鐤紝涓嬪畾鍐冲績寰€鍓嶅啿锛?/p>

瀛︿範鏄渶瑕侀暱鏈熷潥鎸佺殑锛屼竴姝ヤ竴涓剼鍗板湴璧板悜鏈潵锛?/p>

鏈潵鐨勪綘涓€瀹氫細鎰熻阿浠婂ぉ瀛︿範鐨勪綘銆?/p>

鈥斺€?蹇冪伒楦℃堡

鏈枃绔犲埌杩欓噷灏辩粨鏉熷暒~鎰熷叴瓒g殑灏忎紮浼村彲浠ュ鍒朵唬鐮佸幓璇曡瘯鍝?馃槤

Python 采集 快手 实现视频批量保存,第13张

https://www.xamrdz.com/web/2xj1994023.html

相关文章: