Last active
March 12, 2016 19:19
-
-
Save sajibsrs/9715705e796f2f9a2778 to your computer and use it in GitHub Desktop.
A simple python program to get the list of top 50 animated movies of 2015.
This file contains hidden or 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
from lxml import html | |
import requests | |
from operator import itemgetter, attrgetter, methodcaller | |
# IMDB search listing page for "Animated movies 2015" | |
page = requests.get('http://www.imdb.com/search/title?genres=animation&sort=moviemeter,asc&title_type=feature&year=2015') | |
tree = html.fromstring(page.content) | |
# This will create a list of movie names | |
get_names = tree.xpath('//td[@class="title"]/a/text()') | |
# This will create a list of movie rating | |
get_ratings = tree.xpath('//span[@class="rating-rating"]/span[@class="value"]/text()') | |
# Created a zip from the two lists | |
movie_list_unsorted = zip(get_names, get_ratings) | |
# Sort the unsorted zip by user ratings | |
# see - Operator Module Functions @ https://wiki.python.org/moin/HowTo/Sorting | |
movie_list_sorted = sorted(movie_list_unsorted, key=itemgetter(1), reverse=True) | |
# print movies_sorted | |
for movie in movie_list_sorted: | |
print movie |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment