抖音怎么下载别人的作品(抖音别人的作品怎么保存不了)
抖音怎么下载别人的作品(抖音别人的作品怎么保存不了)
要批量下载抖音某博主的视频,并将视频的内容文本保存,可以使用Python中的requests和beautifulsoup库来实现。具体步骤如下:
1. 使用requests库来获取抖音某博主的主页html代码。
“`python
import requests
url = 'https://c.quk.cc/2/b4/13pcdit0bbp
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299'
}
response = requests.get(url, headers=headers)
html = response.text
“`
其中,xxxxxx为该博主的抖音ID。
2. 使用beautifulsoup库来解析html代码,获取该博主的视频列表。
“`python
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')
video_list = soup.find_all('div', {'class': 'video-card'})
“`
其中,'video-card'是抖音视频卡片的class名称。
3. 对于每个视频,使用正则表达式来获取视频的下载链接,并使用requests库下载视频。
“`python
import re
for video in video_list:
video_url = re.findall(r'"playAddr":"(.*?)"', str(video))[0].encode('utf-8').decode('unicode_escape')
video_title = video.find('p', {'class': 'desc'}).text
video_response = requests.get(video_url, headers=headers)
with open(video_title + '.mp4', 'wb') as f:
f.write(video_response.content)
“`
其中,video_url为视频的下载链接,video_title为视频的标题。
4. 对于每个视频,使用正则表达式来获取视频的文本内容,并保存到文本文件中。
“`python
for video in video_list:
video_url = re.findall(r'"playAddr":"(.*?)"', str(video))[0].encode('utf-8').decode('unicode_escape')
video_title = video.find('p', {'class': 'desc'}).text
video_response = requests.get(video_url, headers=headers)
with open(video_title + '.mp4', 'wb') as f:
f.write(video_response.content)
video_html = video.find('a', {'class': 'video-title'}).get('href')
video_response = requests.get(video_html, headers=headers)
video_soup = BeautifulSoup(video_response.text, 'html.parser')
video_text = video_soup.find('div', {'class': 'body'}).text
with open(video_title + '.txt', 'w', encoding='utf-8') as f:
f.write(video_text)
“`
其中,video_html为视频的详情页链接,video_text为视频的文本内容。
完整代码如下:
“`python
import requests
from bs4 import BeautifulSoup
import re
url = 'https://c.quk.cc/2/b4/13pcdit0bbp
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299'
}
response = requests.get(url, headers=headers)
html = response.text
soup = BeautifulSoup(html, 'html.parser')
video_list = soup.find_all('div', {'class': 'video-card'})
for video in video_list:
video_url = re.findall(r'"playAddr":"(.*?)"', str(video))[0].encode('utf-8').decode('unicode_escape')
video_title = video.find('p', {'class': 'desc'}).text
video_response = requests.get(video_url, headers=headers)
with open(video_title + '.mp4', 'wb') as f:
f.write(video_response.content)
video_html = video.find('a', {'class': 'video-title'}).get('href')
video_response = requests.get(video_html, headers=headers)
video_soup = BeautifulSoup(video_response.text, 'html.parser')
video_text = video_soup.find('div', {'class': 'body'}).text
with open(video_title + '.txt', 'w', encoding='utf-8') as f:
f.write(video_text)
“`
需要替换代码中的xxxxxx为博主的抖音ID,并安装requests和beautifulsoup库。
-
- 苹果11pro运行内存多大(苹果12pro运行内存多大)
-
2024-01-19 22:57:10
-
- 32空调是几匹(空调50是几匹)
-
2024-01-19 22:54:56
-
- 韩国奔跑吧兄弟(韩国奔跑吧兄弟在哪看)
-
2024-01-19 22:52:41
-
- 玉米冷水下锅煮多久就熟了(玉米冷水下锅要煮几分钟)
-
2024-01-19 22:50:26
-
- 生蚝怎么撬开外壳(生蚝怎么打开它的壳)
-
2024-01-19 22:48:11
-
- 云库房答案(什么叫云库房)
-
2024-01-19 22:45:56
-
- 月经中有像肉一样的血块是什么(大姨妈流出一坨肉糊糊的东西)
-
2024-01-19 22:43:41
-
- app开发创意点子(创意项目点子)
-
2024-01-19 22:41:26
-
- 下上面一个点(下上面一个点是什么字)
-
2024-01-19 22:39:11
-
- 下上面一个点(下上面一个点是什么字)
-
2024-01-19 22:36:56
-
- 聚是一团火散是满天星啥意思(聚是一团火散是满天星相似的短句)
-
2024-01-19 07:36:47
-
- 马是怎么繁殖的(马是怎么繁殖的我的世界)
-
2024-01-19 07:34:32
-
- 距离3米买个55寸电视后悔了(距离电视3米买多大电视)
-
2024-01-19 07:32:18
-
- 如何把手机视频保存到u盘(如何把手机的视频保存到u盘)
-
2024-01-19 07:30:03
-
- 别人要加微信怎么高情商回复(别人要加微信怎么高情商回复他)
-
2024-01-19 07:27:48
-
- 怎么把手机字体变大(怎么把手机字体变大苹果)
-
2024-01-19 07:25:33
-
- 鞋的英语怎么读(鞋的英语怎么读单词)
-
2024-01-19 07:23:18
-
- 四大书法字体是哪四个(四大书法字体是哪四个字体)
-
2024-01-19 07:21:03
-
- 绳怎么读是什么(绳怎么读拼音是什么字)
-
2024-01-19 07:18:48
-
- 正月是农历几月(12月歌)
-
2024-01-19 07:16:33