import re
import urllib.request
from bs4 import BeautifulSoup
from urllib import parse
import requests
import os
import json
#下载视频
def download_video_series(video_links,video_name):
dir=os.path.abspath('.')
video_links=getrealurl(video_links)
work_path=os.path.join(dir+'\\video\\',video_name+'.mp4')
urllib.request.urlretrieve(video_links,work_path)
#获取真实地址
def getrealurl(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0',
'Referer': 'https://www.douyin.com/'
}
response = requests.head(url,headers=headers).headers
#realurl = response.geturl()
return response['location']
#定义数量
count='13'
#定义用户的Id
id='6464910187'
url='https://www.douyin.com/aweme/v1/aweme/post/?user_id='+id+'&count='+count+'&max_cursor=0&aid=1128&_signature=AsOTZRASWBbMqBW38kvHNALDk3'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0',
'Referer': 'https://www.douyin.com/'
}
#print(url)
d=None
json_data=open('jsondata')
data=json_data.read()
json_data.close()
#req=urllib.request.Request(url,d,headers)
#htmlpage=urllib.request.urlopen(req).read()
data=json.loads(data)
list=data['aweme_list']
for i in list:
temp=i['video']['play_addr']
print(temp['url_list'][0])
download_video_series(temp['url_list'][0],temp['uri'])
抖音下载视频
2020-01-19