Slightly simplified &amp; loops through all the links on the first page :<p><pre><code>    import re, youtube_dl
    from bs4 import BeautifulSoup
    from urllib2 import urlopen
    from urllib import quote_plus

    ydl_opts = {}

    soup = BeautifulSoup(urlopen(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;results?search_query=&#x27; + quote_plus(&#x27;linkin&#x27;)).read())
    links = soup.find_all(&#x27;a&#x27;, href=re.compile(r&#x27;watch\?v=&#x27;), class_=&#x27;yt-uix-tile-link&#x27;)
    
    for i, link in enumerate(links):
        print i+1, &#x27;-&#x27;, link.text

    choice = int(raw_input(&quot;Select song index : &quot;))

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([&#x27;http:&#x2F;&#x2F;www.youtube.com&#x2F;&#x27; + links[choice-1].get(&#x27;href&#x27;)])</code></pre>