卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章1829本站已运行4109

WINRAR自动查找官方最新中文无广告版并下载脚本

import requests
import re
from datetime import datetime, timedelta
 
# 目标网页 URL
url = 'https://www.rarlab.com/'
 
# 发送 HTTP GET 请求获取网页内容
response = requests.get(url)
response.raise_for_status()  # 确保请求成功
 
# 使用正则表达式查找连接文字为“Chinese Simplified”的下载链接
pattern = r'href="(/rar/winrar-x64-[^"]+sc\.exe)"[^>]*>Chinese Simplified<'
match = re.search(pattern, response.text, re.IGNORECASE)
 
if match:
    # 补全下载链接
    download_link = f"https://www.rarlab.com{match.group(1)}"
    print(f"找到下载链接: {download_link}")
     
    # 发送 HTTP HEAD 请求获取文件的服务器时间
    head_response = requests.head(download_link)
    server_date = head_response.headers.get('Last-Modified')
     
    if server_date:
        # 将服务器时间转换为 datetime 对象
        server_date = datetime.strptime(server_date, '%a, %d %b %Y %H:%M:%S %Z')
        print(f"文件在服务器的时间: {server_date}")
         
        # 日期往前推一个月
        target_date = server_date - timedelta(days=30)
        file_name = match.group(1).split('/')[-1]
         
        for i in range(60):  # 最多加60天
            # 生成新的日期格式
            new_date_str = target_date.strftime('%Y%m%d')
            new_url_x64 = f"https://www.win-rar.com/fileadmin/winrar-versions/sc/sc{new_date_str}/wrr/{file_name}"
            new_url_x32 = new_url_x64.replace('x64', 'x32')
            print(f"尝试访问: {new_url_x64}")
             
            # 发送 HTTP HEAD 请求测试 x64 文件是否存在
            head_response_x64 = requests.head(new_url_x64)
            if head_response_x64.status_code == 200:
                print(f"x64 文件存在: {new_url_x64}")
                 
                # 下载 x64 文件
                download_response_x64 = requests.get(new_url_x64)
                download_response_x64.raise_for_status()  # 确保下载成功
                 
                # 保存 x64 文件到当前目录
                with open(file_name, 'wb') as file:
                    file.write(download_response_x64.content)
                print(f"x64 文件已下载到当前目录: {file_name}")
                 
                # 发送 HTTP HEAD 请求测试 x32 文件是否存在
                head_response_x32 = requests.head(new_url_x32)
                if head_response_x32.status_code == 200:
                    print(f"x32 文件存在: {new_url_x32}")
                     
                    # 下载 x32 文件
                    download_response_x32 = requests.get(new_url_x32)
                    download_response_x32.raise_for_status()  # 确保下载成功
                     
                    # 保存 x32 文件到当前目录
                    file_name_x32 = file_name.replace('x64', 'x32')
                    with open(file_name_x32, 'wb') as file:
                        file.write(download_response_x32.content)
                    print(f"x32 文件已下载到当前目录: {file_name_x32}")
                else:
                    print(f"x32 文件不存在: {new_url_x32}")
                break
            else:
                print(f"文件不存在: {new_url_x64}")
                target_date += timedelta(days=1)
    else:
        print("无法获取文件的服务器时间")
else:
    print("未找到连接文字为'Chinese Simplified'的下载链接")
如何使用:
  1. 首先安装Python,然后用Python的ide运行以上源码,就可了!
  2. 我们要无广告版本,需要尝试不同的时间来获取正确下载地址,人工尝试慢,然后可以用下面的脚本来尝试。
卓越飞翔博客
上一篇: 删除抖音播放页面的视频简介
下一篇: 解除VBA 密码,适用于新的offices

相关推荐

留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏