Created
December 12, 2017 17:59
-
-
Save tjoen/782d725dc8ce5559a929baa80ca21d68 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
import json | |
from bs4 import BeautifulSoup | |
import urllib2 | |
request_headers = { | |
"Accept-Language": "en-US,en;q=0.5", | |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0", | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
"Referer": "http://thewebsite.com", | |
"Connection": "keep-alive" | |
} | |
def google_video(x): | |
search = x.split() | |
search = '+'.join(map(str, search)) | |
url = 'https://www.google.nl/search?q=%s&tbm=vid&source=lnms&sa=X&ved=0ahUKEwijn4nG8YTYAhUBzaQKHUyRBBkQ_AUICygC&biw=1348&bih=643&dpr=1' % search | |
request = urllib2.Request( url, headers=request_headers) | |
resp = urllib2.urlopen(request).read() | |
soup = BeautifulSoup(resp,"html.parser") | |
links = soup.find_all('h3',attrs={"class" : "r"}) | |
videos = [] | |
for h3 in links: | |
for link in h3.find_all('a'): | |
videos.append( link.get('href') ) | |
return videos[0] | |
print google_video("beasty boys") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment