Advertisement
Alexquickdraw

Youtube search in python without API key

Jan 7th, 2017
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #Youtube search without API Key.
  2. #Using Python 3.4.2
  3. #By Hardware@chatango.
  4.  
  5. def yt(s):
  6.     s = str(s).replace(" ", "+")
  7.     link = "https://www.youtube.com/results?search_query="+s
  8.     a = urlreq.urlopen(link)
  9.     b = a.read().decode("UTF-8").strip()
  10.     findUrls = re.findall('<a href="(.*?)" class="yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-sessionlink      spf-link ', str(b))
  11.     randomUrl = random.choice(findUrls)
  12.     myUrl = "https://www.youtube.com"+randomUrl
  13.     findData = urlreq.urlopen(myUrl)
  14.     data = findData.read().decode("UTF-8")
  15.     findTitle = re.search('<span id="eow-title" class="watch-title" dir="ltr" title="(.*?)">', str(data))
  16.     return myUrl+"\r"+findTitle.group(1)
  17.    
  18.  
  19.                              
  20.  
  21. print(yt("pokemon"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement