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

2024-04-26 12:18:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我想制作一个程序,打印播放列表中的所有视频名称,但第10行出现“'str'对象不可调用”错误。我怎样才能修好它,谢谢

from pytube import YouTube
from pytube import Playlist

p = Playlist("https://www.youtube.com/watch?v=p6IIWuwdNIc&list=PL3-sRm8xAzY-556lOpSGH6wVzyofoGpzU")
for url in p.video_urls[:10]:
    videourl = url

yt = YouTube(videourl)  
videonames = yt.title()

print(videonames)

Tags: 对象fromimport程序名称url视频youtube
1条回答
网友
1楼 · 发布于 2024-04-26 12:18:19

使用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)

相关问题 更多 >