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

简单爬虫案例——爬取快手视频

网址:aHR0cHM6Ly93d3cua3VhaXNob3UuY29tL3NlYXJjaC92aWRlbz9zZWFyY2hLZXk9JUU2JThCJTg5JUU5JTlEJUEy

找到视频接口:

视频链接在photourl中

 

完整代码:

import requestsimport 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).contentwith open('快手video//'+title+'.mp4','wb') as f:f.write(content)

结果展现:

 

 

http://www.lryc.cn/news/389272.html

相关文章:

  • 42、nginx之nginx.conf
  • 高薪程序员必修课-java为什么要用并发编程
  • postgreSQL学习
  • 【3】系统标定
  • 网安小贴士(3)网安协议
  • 大数据面试题之HBase(1)
  • git回退commit的方式
  • [Information Sciences 2023]用于假新闻检测的相似性感知多模态提示学习
  • 自定义vue3 hooks
  • 《昇思25天学习打卡营第21天 | 昇思MindSporePix2Pix实现图像转换》
  • 【文档+源码+调试讲解】科研经费管理系统
  • linux 下 rm 为什么要这么写?
  • 【Spring Boot】Spring AOP中的环绕通知
  • docker部署前端,配置域名和ssl
  • 初学Spring之 IOC 控制反转
  • rpc的仅有通信的功能,在网断的情况下,比网通情况下,内存增长会是什么原因
  • 从零开始:如何设计一个现代化聊天系统
  • 香橙派OrangePi AIpro初体验:当小白拿到一块开发板第一时间会做什么?
  • 【C语言内存函数】
  • Mysql部署MHA高可用
  • 【算法学习】射线法判断点在多边形内外(C#)以及确定内外两点连线与边界的交点
  • SQL语句(DML)
  • uniapp小程序打开地图导航
  • webstorm格式化或保存时 vue3引入的组件被删除了
  • Java时间转换
  • Spring Boot与WebFlux的实战案例
  • vue3引入本地静态资源图片
  • git 禁止dev合并到任何其他分支
  • 第二节:如何使用thymeleaf渲染html(自学Spring boot 3.x的第一天)
  • 计算机相关术语科普之什么叫网关(Gateway)