最近在研究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   喜欢的支持下了~

最新文章

  1. arcgis server之路网服务发布
  2. U盘操作系统,Kali Linux操作系统安装
  3. 版本控制与vermagic
  4. 剑指offer系列59---寻找丑数
  5. get_template_part() 函数详解备忘(转)
  6. Linux上程序执行的入口--Main
  7. SVN:Cleanup failed to process the following paths
  8. px em rem的详解与区别
  9. BigInteger详解
  10. Git Bash+EGit在项目中配合使用最常用方法总结(根据场景使用)
  11. Tomcat实现反向代理
  12. hotplug/mdev机制
  13. JS:Math 对象方法
  14. Welcom to Swift
  15. SQL 删除的三个语句:DROP、TRUNCATE、 DELETE 的区别
  16. Android动画模式
  17. eclipse测试链接sql server2008 数据库
  18. 一个简易的allocator
  19. 别人的Linux私房菜(7)文件与目录管理
  20. PAT甲级题解(慢慢刷中)

热门文章

  1. h5 Visibility API总结
  2. BFC,IFC,GFC,FFC
  3. 通过VS2010性能分析来查找代码中那些地方最损耗资源
  4. ngrepeat 时注意的地方和一些little tricks
  5. LNMP下安装phpmyadmin的一个小错误解决办法
  6. c# 动态调用webservice 转录一下
  7. It运维项目整理
  8. [poj_3469]多核CPU
  9. iOS crash 崩溃问题的追踪方法
  10. springBoot Ribbon Hystrix Dashboard