python下载抖音视频
时间: 2023-09-02 11:14:30 浏览: 189
使用Python可以实现自动下载抖音视频。首先,你需要导入pandas、requests和os库。然后,可以通过读取一个包含抖音视频链接的CSV文件来获取视频链接。接下来,可以使用requests库发送请求获取视频内容,并将其保存到指定文件夹中。以下是具体的代码实现:
```
import pandas as pd
import requests
import os
num = 0
dom = []
folder_path = "F:/video/"
os.makedirs(folder_path)
df = pd.read_csv('douyin.csv', header=None, names=["url"])
# 对链接去重及去除刚进入抖音获取的视频链接
for i in df['url'][2:]:
if i not in dom:
dom.append(i)
# 下载视频
for j in dom:
url = j
num += 1
response = requests.get(url, stream=True)
filename = str(num) + '.mp4'
with open('F:\\video\\' + filename, 'ab') as f:
f.write(response.content)
f.flush()
print(filename + '下载完成')
```
通过运行上述代码,你可以将抖音视频下载到指定文件夹中。请注意,在运行之前,你需要先准备一个包含抖音视频链接的CSV文件,并将其命名为'douyin.csv',并确保文件路径正确。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [用Python全自动下载抖音视频!](https://blog.csdn.net/cainiao_python/article/details/92802623)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文