-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIMDB.py
More file actions
34 lines (27 loc) · 1.33 KB
/
Copy pathIMDB.py
File metadata and controls
34 lines (27 loc) · 1.33 KB
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
28
29
30
31
32
33
34
import openpyxl
import requests
from bs4 import BeautifulSoup
sourceCode = requests.get("https://www.imdb.com/chart/top")
parsedData = BeautifulSoup(sourceCode.text, 'html.parser')
movieDetails = parsedData.find('tbody', class_="lister-list").find_all('tr')
excel = openpyxl.Workbook()
sheet = excel.active
sheet.title = "Top Charts Movies"
sheet.append(['Movie Rank', 'Movie Name/Year', 'Movie Ratings'])
for details in movieDetails:
movieName = details.find('td', class_='titleColumn').find('a').text
movieRank = details.find('td', class_='titleColumn').get_text(strip=True).split('.')[0]
movieRelease = details.findNext('td', class_='titleColumn').find('span').text
movieRating = details.findNext('td', class_='ratingColumn imdbRating').find('strong').text
movieNameRelease = movieName + '-' + movieRelease
sheet.append([movieRank, movieNameRelease, movieRating])
excel.save('IMDBRatings.xlsx')
w = openpyxl.load_workbook("IMDBRatings.xlsx")
worksheet = w.active
def searchmovies(searchMovie):
for i in range(0, worksheet.max_row):
for j in worksheet.iter_cols(1, worksheet.max_column - 1):
if j[i].value == searchMovie:
return j[i].value + ", The rank is " + worksheet.cell(row=i + 1, column=1).value
return 0
print(searchmovies("Fight Club-(1999)"))