Skip to content

Instantly share code, notes, and snippets.

@cderwin
Created April 19, 2019 23:07
Show Gist options
  • Save cderwin/a7f1386d290d5724e620cd22d28429a1 to your computer and use it in GitHub Desktop.
Save cderwin/a7f1386d290d5724e620cd22d28429a1 to your computer and use it in GitHub Desktop.
def get_youtube_url(artist, song):
r = requests.get('https://www.youtube.com/results', params={'search_query': '{} {} official music video'.format(artist, song)})
soup = BeautifulSoup(r.text)
videos = soup.findAll('a', {'class': 'yt-uix-tile-link'})
while not videos[0]['href'].startswith('/'):
videos = videos[1:]
return 'https://www.youtube.com/' + videos[0]['href']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment