-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
27 lines (21 loc) · 952 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from bs4 import BeautifulSoup
import requests as requests
import openpyxl
excel = openpyxl.Workbook()
sheet = excel.active
sheet.title = 'Top Rated IMDB movies'
sheet.append(['Movie Rank', 'Movie Name', 'Release Year', 'IMDB Rating'])
try:
source = requests.get('https://www.imdb.com/chart/top/?ref_=nv_mv_250')
source.raise_for_status()
soup = BeautifulSoup(source.text,'html.parser')
movies = soup.find('tbody', class_='lister-list').find_all('tr')
for movie in movies:
name = movie.find('td', class_="titleColumn").a.text
rank = movie.find('td', class_="titleColumn").get_text(strip=True).split('.')[0]
year = movie.find('td', class_="titleColumn").span.text.strip("()")
rating = movie.find('td', class_="ratingColumn imdbRating").strong.text
sheet.append([rank, name, year, rating])
except Exception as e:
print(e)
excel.save('IMDB Movie Ratings.xlsx')