├── requirements.txt ├── Pic ├── run.gif ├── UserID.png ├── logo.png └── video.png ├── README.md └── Spiders └── douyin_video.py /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.18.4 2 | -------------------------------------------------------------------------------- /Pic/run.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Henryhaohao/DouYin_Video/HEAD/Pic/run.gif -------------------------------------------------------------------------------- /Pic/UserID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Henryhaohao/DouYin_Video/HEAD/Pic/UserID.png -------------------------------------------------------------------------------- /Pic/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Henryhaohao/DouYin_Video/HEAD/Pic/logo.png -------------------------------------------------------------------------------- /Pic/video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Henryhaohao/DouYin_Video/HEAD/Pic/video.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 抖音APP视频下载 ![enter image description here](Pic/logo.png) 2 | =========================== 3 | ![](https://img.shields.io/badge/Python-3.6.3-green.svg) ![](https://img.shields.io/badge/requests-2.18.4-green.svg) 4 | ### 抖音APP官网 - https://www.douyin.com/ 5 | |Author|:sunglasses:Henryhaohao:sunglasses:| 6 | |---|--- 7 | |Email|:hearts:1073064953@qq.com:hearts: 8 | 9 | 10 | **** 11 | ## :dolphin:声明 12 | ### 软件均仅用于学习交流,请勿用于任何商业用途!感谢大家! 13 | ## :dolphin:介绍 14 | ### 该项目为[抖音APP](https://www.douyin.com/)视频下载 15 | - 项目介绍:通过传入抖音作者的UserID爬取其作者的喜欢(别人的视频)或者发布(自己上传的视频) 16 | - 爬虫文件:Spiders目录下的douyin_video.py 17 | - 运行方法:传入抖音作者的UserID(此参数位置参考下方的截图)即可开始下载视频,下载的视频将存放在项目目录下的douyin_video文件夹中 18 | - 抖音作者URL链接示例: https://www.douyin.com/share/user/63692754272/ (哈哈:smile:这是我的抖音号~) 19 | ## :dolphin:运行环境 20 | Version: Python3 21 | ## :dolphin:安装依赖库 22 | ``` 23 | pip3 install -r requirements.txt 24 | ``` 25 | ## :dolphin:运行截图 26 | > - **URL链接中获取UserID (注意:UserID是链接中的63692754272,而不是下面的抖音ID)**

27 | ![enter image description here](Pic/UserID.png) 28 | 29 | > - **运行下载**

30 | ![enter image description here](Pic/run.gif) 31 | 32 | > - **下载完成**

33 | ![enter image description here](Pic/video.png) 34 | ## :dolphin:**总结** 35 | > **最后,如果你觉得这个项目不错或者对你有帮助,给个Star呗,也算是对我学习路上的一种鼓励!
36 | 哈哈哈,感谢大家!笔芯~**:cupid::cupid: 37 | 38 | 39 | -------------------------------------------------------------------------------- /Spiders/douyin_video.py: -------------------------------------------------------------------------------- 1 | # !/user/bin/env python 2 | # -*- coding:utf-8 -*- 3 | # time: 2018/7/22--22:07 4 | __author__ = 'Henry' 5 | 6 | ''' 7 | 抖音视频下载 8 | ''' 9 | 10 | # 注意:爬取中间会出现{'cursor': 10, 'status_code': 0, 'has_more': 1, 'aweme_list': []},取不到视频,一直请求即可 11 | 12 | import requests, re, sys, os, time 13 | 14 | # 增加函数递归次数 15 | sys.setrecursionlimit(1000000) 16 | # 获取dytk值(每个id,dytk值是固定的) 17 | def get_param(user_id): 18 | url = 'https://www.douyin.com/share/user/{}/'.format(user_id) 19 | headers = { 20 | 'upgrade-insecure-requests': '1', 21 | 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' 22 | } 23 | html = requests.get(url, headers=headers).text 24 | dytk = re.search("dytk: '(.*?)'", html).group(1) 25 | params = { 26 | 'user_id': str(user_id), 27 | 'count': '35', # 默认21,写再大最多也就一次35个视频 28 | 'max_cursor': '0', # 开始爬取的标记 29 | 'aid': '1128', 30 | # '_signature': signature, # signature可以不带(js加密的) 31 | 'dytk': dytk, 32 | } 33 | return params 34 | 35 | # 下载喜欢的视频(音乐已经下载不到了,music字段为空) 36 | num = 1 37 | def get_favor_video(param,max_cursor=None): 38 | if not os.path.exists('douyin_video'): 39 | os.mkdir('douyin_video') 40 | if max_cursor: 41 | param['max_cursor'] = str(max_cursor) 42 | url = 'https://www.douyin.com/aweme/v1/aweme/favorite/' 43 | headers = { 44 | 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36', 45 | 'referer': 'https://www.douyin.com/share/user/{}/'.format(user_id), 46 | } 47 | html = requests.get(url=url, params=param, headers=headers).json() 48 | content = html.get('aweme_list') 49 | print(html) 50 | if content: 51 | for i in content: 52 | global num # 在函数中引用函数外定义的变量就要用全局变量引用 53 | # 标题 54 | title = i['share_info']['share_desc'] 55 | # 清洗一下标题名称(不能有\ / : * ? " < > |) 56 | title = re.sub(r'[\/\\:*?"<>|]', '', title) # 替换为空的 57 | print(str(num) + '-' + title) 58 | # 视频地址 59 | video_uri = i['video']['play_addr']['uri'] 60 | video = 'https://aweme.snssdk.com/aweme/v1/playwm/?video_id={}'.format( 61 | video_uri) # 原来可以playwm去掉wm,下载无水印视频;现在不行了 62 | print(video) 63 | # 下载视频 64 | mp4 = requests.get(video, headers=headers, stream=True).content # 必须加上headers,不然跳转失败!!! 65 | open('douyin_video\\{}-{}.mp4'.format(num, title), 'wb').write(mp4) 66 | num = num + 1 67 | if max_cursor: 68 | print(max_cursor) 69 | if html['has_more'] == 1: 70 | return get_favor_video(param,html.get('max_cursor')) 71 | else: 72 | print('下载结束...') 73 | end_time = time.time() # 结束时间 74 | print("一共下载了%s个抖音视频,总耗时%.2f秒,大约%.2f分钟" % (num, end_time - start_time, int(end_time - start_time) / 60)) 75 | exit() 76 | 77 | # 获取作者的作品(就把url改成'https://www.douyin.com/aweme/v1/aweme/post/') 78 | 79 | 80 | if __name__ == '__main__': 81 | user_id = input('请输入您要爬取的作者的ID:') # 不是抖音ID,是url中的ID(见UserID.png) 82 | start_time = time.time() 83 | param = get_param(user_id) 84 | get_favor_video(param) 85 | --------------------------------------------------------------------------------