Created
April 19, 2019 23:07
-
-
Save cderwin/a7f1386d290d5724e620cd22d28429a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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