|
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=VnifkJhOS6U') print(yt.captions) caption = yt.captions['zh-TW'] srt = caption.generate_srt_captions() file = open('download/youtube.srt', 'w', encoding='UTF-8') file.write(srt) file.close() print(srt)
問題 {} ----------------------------------- KeyError Traceback (most recent call last) <ipython-input-12-bcf18f39a03d> in <module> 3 yt = YouTube('https://www.youtube.com/watch?v=VnifkJhOS6U') 4 print(yt.captions) ----> 5 caption = yt.captions['zh-TW'] 6 srt = caption.generate_srt_captions() 7 file = open('download/youtube.srt', 'w', encoding='UTF-8')
C:\ProgramData\Anaconda3\lib\site-packages\pytube\query.py in __getitem__(self, i) 410 411 def __getitem__(self, i: str): --> 412 return self.lang_code_index[i] 413 414 def __len__(self) -> int:
KeyError: 'zh-TW' |