import requests
from bs4 import BeautifulSoup

def FromTestToInt(txt):
	if u'\xa0' in txt:
		return int(txt.replace(u'\xa0',u''))
	else:
		return int(txt)

def GetSoupFromUrl(url):
	request=requests.get(url)
	return BeautifulSoup(request.text, 'html.parser')

def GetButton(soup,info):
	InfoButton=soup.findAll("button", { "class" : info})[0]
	Info=InfoButton.findAll( "span", {"class" : "yt-uix-button-content"})[0].text
	return FromTestToInt(Info)

def GetInformation(soup):
	like=GetButton(soup,"like-button-renderer-like-button")
	print 'like:', like
	dislike=GetButton(soup,"like-button-renderer-dislike-button")
	print 'dislike:', dislike	
	nbview=soup.findAll("div", { "class" : "watch-view-count" })[0].text
	intnbview=FromTestToInt(nbview)
	print 'NbView:',intnbview
	print('#####')

def artiste(name):
	for nbpage in range(1,2):
		url='https://www.youtube.com/results?search_query='+name+'&page='+str(nbpage)
		soup = GetSoupFromUrl(url)
		tiles_links = soup.findAll("a", { "class" : "yt-uix-tile-link" })
	
		for title in tiles_links:
			 if 'watch' in title['href']:
			 	print(title['href'])
				newurl='https://www.youtube.com'+title['href']
				soupInfo = GetSoupFromUrl(newurl)
				GetInformation(soupInfo)

artiste('Rihana')