1. 使用requests库来获取抖音某博主的主页html代码。
```python
import requests
url = 'https://www.douyin.com/user/xxxxxx'
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://www.douyin.com/user/xxxxxx'
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库。
以上便是小编为大家带来的怎么保存别人的抖音视频,希望对大家有所帮助,更多内容请继续关注鼎品软件。
龙武士李小龙破解版
动作格斗108.87MB
下载保卫萝卜四
策略塔防170.9M
下载现代战争2019无限金币版
飞行射击33.9M
下载途游游戏平台手游官网版
卡牌桌游70M
下载叶罗丽美颜公主游戏
模拟经营69.4M
下载卡通农场
模拟经营146.18M
下载元气少女恋爱手册
模拟经营214.01 MB
下载饥饿的蟒蛇模拟器无限金币版
休闲益智53.6M
下载音乐赛车苹果版
赛车竞速195KB
下载宝可梦我的世界
模拟经营135MB
下载