如何使用 Python 打印播放列表中的所有视频名称?

时间:2021-06-30 18:09:00

标签: python pytube

我想制作一个程序来打印播放列表中的所有视频名称,但在第 10 行出现“'str' object is not callable”错误。我该如何解决,谢谢!

enter

1 个答案:

答案 0 :(得分:1)

使用 title 而不是 title()

from pytube import YouTube
from pytube import Playlist

playlist = Playlist("https://www.youtube.com/watch?v=p6IIWuwdNIc&list=PL3-sRm8xAzY-556lOpSGH6wVzyofoGpzU")

# Print first 10 video names in playlist
for url in playlist.video_urls[:10]:
    yt = YouTube(url)
    video_name = yt.title
    print(video_name)

输出:

DaBaby - Red Light Green Light (Official Video)
Internet Money - His & Hers ft. Don Toliver, Lil Uzi Vert & Gunna (Directed by Cole Bennett)
Wale - Angles (feat. Chris Brown) [Official Music Video]
DDG & OG Parker - Hood Melody ft. YoungBoy Never Broke Again (Official Music Video)
Remble - Touchable (Official Music Video)
Baby Keem, Travis Scott - durag activity (Official Video)
J. Cole - p r i d e . i s . t h e . d e v i l  feat. Lil' Baby (Official Audio)
Isaiah Rashad - Headshots (4r Da Locals) [Official Music Video]
DaBaby - BALL IF I WANT TO (Official Video)
Joyner Lucas - Legend ft. Rick Ross (Official Video)