lua/script/circle_down.lua
2025-03-22 10:49:30 +08:00

84 lines
2.3 KiB
Lua

-- 定义基础URL
local base_url = "https://www.xxx.com"
-- 函数:验证输入是否合法
local function validate_input(input)
local a, b = input:match("^(%d+),(%d+)$")
if a and b then
a = tonumber(a)
b = tonumber(b)
if a <= b then
return a, b
end
end
return nil
end
-- 函数:拼接URL列表
local function generate_urls(a, b)
local urls = {}
for i = a, b do
table.insert(urls, base_url .. "/" .. i)
end
return urls
end
-- 函数:执行URL并处理失败情况
local function execute_urls(urls)
local failed_urls = {}
for _, url in ipairs(urls) do
local success = os.execute("curl -I " .. url) -- 使用curl命令检查URL是否可访问
if not success then
print("执行失败: " .. url)
io.write("是否重试? (y/n): ")
local retry = io.read()
if retry == "y" then
success = os.execute("curl -I " .. url)
if not success then
table.insert(failed_urls, url)
end
else
table.insert(failed_urls, url)
end
end
end
return failed_urls
end
-- 函数:将失败的URL保存到文件
local function save_failed_urls(failed_urls)
if #failed_urls > 0 then
local file = io.open("failed_urls.txt", "w")
if file then
for _, url in ipairs(failed_urls) do
file:write(url .. "\n")
end
file:close()
print("失败的URL已保存到 failed_urls.txt")
else
print("打开文件失败。")
end
else
print("所有URL执行成功,没有失败的URL。")
end
end
-- 主程序
while true do
io.write("请输入起始数字a和终止数字b(格式为a,b)或输入re重新开始: ")
local input = io.read()
if input == "re" then
print("重新开始...")
else
local a, b = validate_input(input)
if a and b then
local urls = generate_urls(a, b)
local failed_urls = execute_urls(urls)
save_failed_urls(failed_urls)
break
else
print("输入格式不正确或a > b,请重新输入。")
end
end
end