!pip install pysrt
from typing import Text
import pysrt
import pandas as pd
# 读取字幕文件
subs = pysrt.open(r'xxx.srt')
# 文件包含三列:开始时间,结束时间,字幕
df = pd.DataFrame(columns=('Start time', 'End time', 'Text'))
# 写入data frame
i = 1
for sub in subs:
start_time = sub.start.to_time()
end_time = sub.end.to_time()
text = sub.text
df.loc[len(df.index)] = [start_time, end_time, text]
i+= 1
# 保存为xlsx
df.to_excel('xxx.xlsx', index=False)