import re
import subprocess
from timeout_decorator import timeout, TimeoutError
timeout_seconds = 5 # 超时事件 (秒)
# 定义超时装饰器
@timeout(timeout_seconds)
def run_command(command):
return subprocess.run(command, shell=True)
# head url 字符串
head = "https://mirrors.ustc.edu.cn/CTAN/systems/win32/miktex/tm/packages/"
# 使用正则表达式匹配链接和文件名
target_pattern = r'<a href="([^"]+.tar.lzma)">([^<]+.tar.lzma)</a>'
# 打开文件
with open('theweb.html', 'r') as file:
# 逐行读取并输出文件内容
for line in file:
# 使用strip()方法去除每行末尾的换行符
line = line.strip()
match = re.search(target_pattern, line)
if match:
filename = match.group(1)
url = head + filename
command = "wget -O - " + url + " > " + filename
ret = 1
while 0 != ret:
try:
retval = run_command(command)
ret = retval.returncode
except TimeoutError:
print("after timeouterror")
continue # 继续循环
01-17
980
10-19
244