• python实现抖音多线程下载无水印视频【附源码】


        昨天发了一个无水印解析,评论说想要多线程下载,还是比较简单的。 py文件同目录下创建url.txt,把链接一行一行复制进去,就能批量下载。

        代码中的延时不能去掉,由于是多线程,速度较快,延时很重要。

        

    import re
    import requests
    from concurrent import futures
    import time
    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36'}
    def download(_url):
        try:
            time.sleep(0.3)
            html3 = requests.head(_url,headers = headers)
            download_url = html3.headers['Location']
            video_file = requests.get(download_url,headers = headers)
            file_name = download_url.split('=')[-1]
            print(file_name)
        except:
            print('Error')
        with open(file_name + '.mp4','wb') as code:
            code.write(video_file.content)
    def main():
        data_file = open('url.txt')
        data_url = data_file.read()
        data_url_list1 = data_url.split('
    ')
        Threads = futures.ThreadPoolExecutor(min(Max_workers,len(data_url_list1)))
        for x in data_url_list1:
            html1 = requests.head(x)
            first_url = html1.headers['Location']
            html2 = requests.get(first_url,headers = headers)
            text_data = html2.text
            video_player_url1 = re.findall('playAddr: "(.*?)"',text_data,re.S)[0]
            video_player_url2 = video_player_url1.replace('wm','')
            #download(video_player_url2)
            Threads.submit(download,video_player_url2)
    Max_workers = 5       
    main()
    

      

      

  • 相关阅读:
    数据一致性
    linux下关于程序性能和系统性能的工具、方法
    关于网站架构的一些文章
    列出man手册所有函数的方法
    dup和dup2函数以及管道的实现
    knowledge about apache
    第三篇 读后感
    课程作业02
    《大道至简》第二篇读后感
    课程作业01
  • 原文地址:https://www.cnblogs.com/68xi/p/10425277.html
Copyright © 2020-2023  润新知