Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import requests
- done = False
- while not done:
- try:
- url = raw_input("IMDB URL: ")
- # get the IMDB page
- r = requests.get(url)
- data = r.text
- # and parse it with BeautifulSoup
- soup = BeautifulSoup(data)
- # the td containing what we're looking for
- td = soup.find('td', {'id': 'overview-top'})
- rating = td.find('div', {'class': 'star-box-giga-star'}).string
- plot = td.find('p', {'itemprop': 'description'}).string
- # the div containing the main actors in the cast
- actors = td.find('div', {'itemprop': 'actors'})
- stars = ', '.join([actor.string for actor in actors.find_all('span', {'class': 'itemprop', 'itemprop': 'name'})])
- print '*%s* - %s. %s' % (rating.strip(), stars, plot)
- except KeyboardInterrupt:
- done = True
- print
- print 'bye!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement