68xi

    昨天发了一个无水印解析,评论说想要多线程下载,还是比较简单的。 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(\'\n\')
    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()

  

  

分类:

技术点:

相关文章:

  • 2021-06-27
  • 2021-12-18
  • 2021-12-10
  • 2021-11-30
  • 2021-06-21
  • 2022-01-05
  • 2022-01-17
  • 2021-05-19
猜你喜欢
  • 2021-08-05
  • 2021-09-11
  • 2021-12-24
  • 2021-12-11
  • 2022-12-23
  • 2021-06-08
相关资源
相似解决方案