简单爬虫案例——爬取快手视频
创始人
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、系统规律教程、辅助透...
透视透视挂!德扑圈透视,新西部... 透视透视挂!德扑圈透视,新西部透视挂辅助器,科技教程(有挂揭秘)1、用户打开应用后不用登录就可以直接...
第九分钟辅助!大唐撸麻雀作弊码... 第九分钟辅助!大唐撸麻雀作弊码(辅助挂)确实真的是有挂(详细辅助安装教程);小薇(透视辅助)致您一封...
详细说明“新超凡辅助app链接... 详细说明“新超凡辅助app链接”都是存在有挂(辅助挂)详细辅助2025新版1、完成的残局,帮助玩家取...
透视真的!哈糖大菠萝怎么挂,都... 透视真的!哈糖大菠萝怎么挂,都莱软件安装辅助,详细教程(有挂解密)都莱软件安装辅助辅助器中分为三种模...
五分钟辅助!逍遥辅助器手机版(... 五分钟辅助!逍遥辅助器手机版(辅助挂)一向有挂(详细辅助教你攻略)1、很好的工具软件,可以解锁游戏的...
总算了解“科乐天天踢起手拿好牌... 总算了解“科乐天天踢起手拿好牌”竟然有挂(辅助挂)详细辅助力荐教程;1、ai辅助优化,发牌逻辑科技护...
透视软件!hhpoker辅助软... 透视软件!hhpoker辅助软件下载,雀友会广东潮汕辅助透视,2025新版(有挂细节)1、雀友会广东...
第7分钟辅助!欢乐茶馆免费辅助... 第7分钟辅助!欢乐茶馆免费辅助设置(辅助挂)原生是真的有挂(详细辅助第三方教程);小薇(透视辅助)致...
记者揭秘“微友约局辅助”其实真... 记者揭秘“微友约局辅助”其实真的是有挂(辅助挂)详细辅助AI教程1、系统规律教程、辅助透视等服务,为...