当前位置: 首页> 财经> 产业 > 抖音分享链接视频下载

抖音分享链接视频下载

时间:2025/7/9 0:47:22来源:https://blog.csdn.net/qqk808/article/details/139197716 浏览次数:0次

import requests
import re
from urllib.parse import unquote
import json
from pprint import pprint
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os


def get_video_id(url):
    # 创建一个Chrome WebDriver实例
    chrome_options = Options()
    chrome_options.add_argument("--headless")  # This line makes Chrome run in headless mode
    chrome_options.add_argument("--disable-logging")
    # Initialize the WebDriver with the specified options
    driver = webdriver.Chrome(options=chrome_options) 
    # 打开网页
    driver.get(url)
    # 获取跳转后的网址
    final_url = driver.current_url
    # 打印跳转后的网址
    print("跳转后的网址:", final_url)
    # 关闭WebDriver实例
    #driver.quit()
    video_id = final_url.split("/video/")[1]
    return video_id

def download_byid(video_id):
    url ="https://www.douyin.com/discover?modal_id="+video_id
    print(url)
    headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
    # 'Cookie':''
    }
    response = requests.get(url= url,headers=headers)
    print(response)
    html = response.text
    #
    info = re.findall('<script id="RENDER_DATA" type="application/json">(.*?)</script>',html)
    info_json = unquote(info[0])

    #pprint(info_json)
    json_data = json.loads(info_json)

    video_url = 'https:'+json_data['app']['videoDetail']['video']['bitRateList'][0]['playAddr'][0]['src']
    video_title = json_data['app']['videoDetail']['desc']
    pprint(video_url)
    pprint(video_title)
    video_content = requests.get(url = video_url,headers=headers).content
    with open ("download/"+video_id+'.mp4',mode= 'wb')as f:
        f.write(video_content)
    with open ("download/"+video_id+'.txt',mode= 'w', encoding='utf-8')as f:
        f.write(video_title)
    return "download/"+video_id+'.mp4',video_title,video_url


if __name__ == "__main__":
    url2 = 'https://v.douyin.com/i2G6aAcM/'
    print(get_url(url2))
    download(url2)
 

关键字:抖音分享链接视频下载

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: