Skip to content

Instantly share code, notes, and snippets.

@barangerbenjamin
Created April 14, 2021 09:34
Show Gist options
  • Save barangerbenjamin/0e78233c234b43e0ef35da489f985e06 to your computer and use it in GitHub Desktop.
Save barangerbenjamin/0e78233c234b43e0ef35da489f985e06 to your computer and use it in GitHub Desktop.
import requests
import csv
from bs4 import BeautifulSoup
url = "https://www.imdb.com/list/ls055386972/"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
items = soup.find_all("div", class_="lister-item-content")
movies = []
for item in items:
title = item.find("a").string
duration = item.find("span", class_="runtime").string
movies.append({'title': title, 'duration': duration})
with open('data/movies.csv', 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=movies[0].keys())
writer.writeheader()
for movie in movies:
writer.writerow(movie)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment