Python爬取抖音视频
2024-09-01 01:52:09
最近在研究Python爬虫,顺便爬了一下抖音上的视频,找到了哥们喜欢的小姐姐居多,咱们给他爬下来吧.
最终爬取结果
好了废话补多说了,上代码!
#https://www.iesdouyin.com/aweme/v1/aweme/favorite/?user_id=86371592618
#&count=21&max_cursor=0&aid=1128&_signature=fBZqMxAcIH.WOSqz4s5eTHwWai&dytk=6849c66ff2a629554679fe#e4ad1343a5
#分析url https://www.iesdouyin.com/share/user/86371592618
#最终获取用户喜欢
import requests url="https://www.iesdouyin.com/share/user/86371592618"
#抖音本身反爬虫措施
headers={
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
}
#获得dytk
reponse=requests.get(url,headers=headers)
reponse.encoding='utf-8'
#print(reponse.text)
#获得dytk 通过正则进行筛选
import re
dytk=re.search("dytk: '(.*?)'",reponse.text).group(1)
print(dytk) #组装数据
params={
'user_id':'',
'count':'',
'max_cursor': '',
'aid': '',
'dytk': dytk
} aweme_list=[]
def get_favor_video():
#引用全局变量
global aweme_list
while True:
# 请求数据
furl = "https://www.iesdouyin.com/aweme/v1/aweme/favorite/"
jsonstr = requests.get(furl, params=params, headers=headers).json()
print(jsonstr)
# 多次请求会出现正确数据
#修改全局变量的值
aweme_list = jsonstr.get('aweme_list')
print(aweme_list)
if len(aweme_list)!=0:
break get_favor_video() #进行下一步解析
#拼接视频地址
for item in aweme_list:
#读取视频uri
video_uri=item['video']['play_addr']['uri']
#拼接视频地址
video="https://aweme.snssdk.com/aweme/v1/playwm/?video_id="+video_uri
#下载视频
#读取视频名称
title=item['share_info']['share_desc']
#写入视频
mp4=requests.get(video,headers=headers,stream=True).content
open('F:/PythonWork/test/video/' + title+'.mp4', 'wb').write(mp4)
print("下载完成")
个人博客地址 http://zweice.com 喜欢的支持下了~
最新文章
- arcgis server之路网服务发布
- U盘操作系统,Kali Linux操作系统安装
- 版本控制与vermagic
- 剑指offer系列59---寻找丑数
- get_template_part() 函数详解备忘(转)
- Linux上程序执行的入口--Main
- SVN:Cleanup failed to process the following paths
- px em rem的详解与区别
- BigInteger详解
- Git Bash+EGit在项目中配合使用最常用方法总结(根据场景使用)
- Tomcat实现反向代理
- hotplug/mdev机制
- JS:Math 对象方法
- Welcom to Swift
- SQL 删除的三个语句:DROP、TRUNCATE、 DELETE 的区别
- Android动画模式
- eclipse测试链接sql server2008 数据库
- 一个简易的allocator
- 别人的Linux私房菜(7)文件与目录管理
- PAT甲级题解(慢慢刷中)