Python subtitles from youtube

Question:

I wrote a code but it doesn’t work could you help me to find a mistake?

from youtube_transcript_api import YouTubeTranscriptApi
import os

srt = YouTubeTranscriptApi.get_transcript("SW14tOda_kI")
text = ""
with open("file.txt", "w") as file:
    for i in srt:
    text += i["text"] + "n"
    file.write(text)
os.startfile("file.txt")
Asked By: lekarz93

||

Answers:

You have indentation problem. the correct code is:

from youtube_transcript_api import YouTubeTranscriptApi
import os

srt = YouTubeTranscriptApi.get_transcript("SW14tOda_kI")
text = ""
with open("file.txt", "w") as file:
    for i in srt:
        text += i["text"] + "n"
    file.write(text)
os.startfile("file.txt")
Answered By: Phoenix
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.