简单爬虫案例——爬取快手视频
创始人
2025-01-16 15:06:07
0

网址:aHR0cHM6Ly93d3cua3VhaXNob3UuY29tL3NlYXJjaC92aWRlbz9zZWFyY2hLZXk9JUU2JThCJTg5JUU5JTlEJUEy

找到视频接口:

视频链接在photourl中

 

完整代码:

import requests  import re url = 'https://www.kuaishou.com/graphql' cookies = {     'did': 'web_9e8cfa4403000587b9e7d67233e6b04c',     'didv': '1719811812378',     'kpf': 'PC_WEB',     'clientid': '3',     'kpn': 'KUAISHOU_VISION', }  headers = {     'Accept-Language': 'zh-CN,zh;q=0.9',     'Cache-Control': 'no-cache',     'Connection': 'keep-alive',     # 'Cookie': 'did=web_9e8cfa4403000587b9e7d67233e6b04c; didv=1719811812378; kpf=PC_WEB; clientid=3; kpn=KUAISHOU_VISION',     'Origin': 'https://www.kuaishou.com',     'Pragma': 'no-cache',     'Referer': 'https://www.kuaishou.com/search/video?searchKey=%E6%8B%89%E9%9D%A2',     '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/126.0.0.0 Safari/537.36',     'accept': '*/*',     'content-type': 'application/json',     'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',     'sec-ch-ua-mobile': '?0',     'sec-ch-ua-platform': '"Windows"', }  json_data = {     'operationName': 'visionSearchPhoto',     'variables': {         'keyword': '拉面',         'pcursor': '',         'page': 'search',     },     '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 visionSearchPhoto($keyword: String, $pcursor: String, $searchSessionId: String, $page: String, $webPageArea: String) {\n  visionSearchPhoto(keyword: $keyword, pcursor: $pcursor, searchSessionId: $searchSessionId, page: $page, webPageArea: $webPageArea) {\n    result\n    llsid\n    webPageArea\n    feeds {\n      ...feedContent\n      __typename\n    }\n    searchSessionId\n    pcursor\n    aladdinBanner {\n      imgUrl\n      link\n      __typename\n    }\n    __typename\n  }\n}\n', }  response = requests.post(url=url, cookies=cookies, headers=headers, json=json_data) for index in response.json()['data']['visionSearchPhoto']['feeds']:     title = index['photo']['caption']     newtitle = re.sub(r'[\\/?<>:*|\n\r]','',title)     link = index['photo']['photoUrl']     print(title,link)     content = requests.get(url=link,headers=headers).content     with open('快手video//'+title+'.mp4','wb') as f:         f.write(content)

结果展现:

 

 

相关内容

热门资讯

1次plus(WPK打法)透明... 1次plus(WPK打法)透明挂辅助器软件(透视)详细教程(2025已更新)(哔哩哔哩),WPK是用...
十分钟辅助挂wepoke中牌率... 十分钟辅助挂wepoke中牌率(软件透明挂)德州智能辅助(2024已更新)(哔哩哔哩)是一款可以让一...
七次渠道!aa扑克可以调胜率(... 大家肯定在之前或者中玩过七次渠道!aa扑克可以调胜率(软件透明挂)Wepoke透明挂原来真的是有挂(...
3次小程序(WPK内置)透明挂... 3次小程序(WPK内置)透明挂辅助器工具(透视)详细教程(2022已更新)(哔哩哔哩);WPK软件透...
八次测试wpk微扑克(软件透明... 您好,wpk微扑克这款游戏可以开挂的,确实是有挂的,需要了解加微【485275054】很多玩家在这款...
一次苹果版!wepoke用模拟... 一次苹果版!wepoke用模拟器有用(软件透明挂)WPK原来真的有挂(2023已更新)(哔哩哔哩);...
2次苹果红龙扑克都是机器人(软... 自定义新版红龙扑克系统规律,只需要输入自己想要的开挂功能,一键便可以生成出红龙扑克专用辅助器,不管你...
9分钟工具(wpk修改器)外挂... 9分钟工具(wpk修改器)外挂透明挂软件(透视)详细教程(2021已更新)(哔哩哔哩)是一款可以让一...
【MODBUS】J2mod库写... j2mod 是一个用于 Modbus 通信协议的 Java 库,可以用来创建 Modb...
Linux网络-自定义协议、序... 文章目录前言一、自定义协议传结构体对象序列化和反序列化什么是序列化?反序列化二、计算器...