scrapeit/scrapeit/yahootrailers.py
2007-11-30 11:39:50 +00:00

25 lines
No EOL
672 B
Python

# -*- coding: utf-8 -*-
# -*- Mode: Python; -*-
# vi:si:et:sw=2:sts=2:ts=2
from urllib import quote
import re
from BeautifulSoup import BeautifulSoup
from utils import read_url, stripTags
def trailerByTitle(title):
title = title.strip()
url = "http://movies.yahoo.com/mv/search?p=%s" % quote(title)
data = read_url(url)
soup = BeautifulSoup(data)
movies = soup('a', {'href': re.compile('http://movies.yahoo.com/movie.*?')})
if movies and movies[0].firstText() and title in movies[0].firstText():
info = movies[0]['href']
trailer = info.replace('/info', '/video')
data = read_url(info)
if trailer in data:
return trailer
return ''