【问题标题】:search and enter the first youtube video using python使用 python 搜索并输入第一个 youtube 视频
【发布时间】:2014-06-26 12:00:47
【问题描述】:

您好,我在 python 中使用 youtube api。 我希望用户会自动在函数中写一些东西 将搜索他想要的内容,它将进入第一个视频。 我成功搜索了:

def start_song(self,song_name):
    words = song_name.split()

    url = "http://www.youtube.com/results?search_query="

    for word in words:
        url = url + word + "+"

    time.sleep(1)   #Sleeps for a second
    webbrowser.open_new(url)

但是条目我不知道该怎么做。

【问题讨论】:

标签: python youtube youtube-api


【解决方案1】:

考虑到你的“song_name”是一个你想用空格字符分隔单词的句子,你可以试试这个:

def start_song(self,song_name):
    words = song_name.split()

    url = "http://www.youtube.com/results?search_query="

    for word in words:
        url += word + "+"

    time.sleep(1)   #Sleeps for a second
    webbrowser.open_new(url[:-1])  # -1 because we remove the last "+" inserted

【讨论】:

    猜你喜欢
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2012-08-02
    • 2023-01-02
    • 2021-04-07
    • 2015-07-12
    相关资源
    最近更新 更多