Created
July 29, 2016 04:44
-
-
Save jlumpe/49cab714e3cb3d80a759ba1c4980653d to your computer and use it in GitHub Desktop.
Scrape Netflix ratings
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
"""https://www.netflix.com/MoviesYouveSeen""" | |
from bs4 import BeautifulSoup | |
def parse_rating(li): | |
rating = dict() | |
title_elem, = li.select('div.title > a') | |
rating['title'] = title_elem.text | |
rating['link'] = title_elem['href'] | |
rating['date'] = li.select('div.date')[0].text | |
stars_elem, = li.select('div.rating > div.starbar') | |
assert len(stars_elem.select('span.star.icon-star')) == 5 | |
rating['stars'] = len(stars_elem.select('span.star.personal')) | |
return rating | |
def get_ratings(html): | |
soup = BeautifulSoup(html, 'html.parser') | |
table, = soup.find_all('ul', class_='retable') | |
return list(map(parse_rating, table)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment