-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrun.py
More file actions
23 lines (18 loc) · 684 Bytes
/
run.py
File metadata and controls
23 lines (18 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import webbrowser
import requests
from bs4 import BeautifulSoup
'''
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'}
'''
query = input('Enter the title of the video: ')
query = query.replace(' ', '+')
url = 'https://www.youtube.com/results?search_query=' + query
source_code = requests.get(url,timeout=10)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
songs = soup.findAll('div', {'class': 'yt-lockup-video'})
song = songs[0].contents[0].contents[0].contents[0]
link = song['href']
webbrowser.open('https://www.youtube.com' + link)