Skip to content

Instantly share code, notes, and snippets.

@jlumpe
Created July 29, 2016 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlumpe/49cab714e3cb3d80a759ba1c4980653d to your computer and use it in GitHub Desktop.
Save jlumpe/49cab714e3cb3d80a759ba1c4980653d to your computer and use it in GitHub Desktop.
Scrape Netflix ratings
"""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