-def search_youtube(search_strings):
- """ This takes a list of search strings and tries to find the first result. It returns a list of the youtube video ids of those results.
- """
- video_list = []
- for search_string in search_strings:
- search_url = 'http://youtube.com/results?search_query=' + urllib.quote_plus(search_string)
- page = urllib.urlopen(search_url)
- page = BeautifulSoup(page)
- result = page.find('div', attrs={'class':'video-main-content'})
- if result == None:
- print 'odd feedback for search, could not find div at ', search_url
- continue
- for attr, value in result.attrs:
- if attr == 'id' and len(value[19:]) == 11:
- video_list.append(value[19:])
- elif attr == 'id':
- print 'odd feedback for search', search_url, " : ", value[19:]
- return video_list
-
-