我编写了以下脚本来使用 pytube API 从 youtube 下载 mp4 视频:
from pytube import YouTube
import sys
SAVE_PATH = input('Enter a saving path: ')
LINK = input('Enter the link of the video: ')
try:
yt = YouTube(LINK)
except:
print('Connection error')
print(yt.title)
items = yt.streams.filter(only_audio=True).all()
stream = items[0]
stream.download()
当我运行代码时,出现以下错误:
Connection error
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\Python\youtube.py", line 24, in <module>
print(yt.title)
NameError: name 'yt' is not defined
有什么问题,我该如何解决?