File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ import csv
2
+ from typing import Dict
3
+
4
+ import requests
5
+ from bs4 import BeautifulSoup
6
+
7
+
8
+ def get_imdb_top_250_movies (url : str = "" ) -> Dict [str , float ]:
9
+ url = url or "https://www.imdb.com/chart/top/?ref_=nv_mv_250"
10
+ soup = BeautifulSoup (requests .get (url ).text , "html.parser" )
11
+ titles = soup .find_all ("td" , attrs = "titleColumn" )
12
+ ratings = soup .find_all ("td" , class_ = "ratingColumn imdbRating" )
13
+ return {
14
+ title .a .text : float (rating .strong .text )
15
+ for title , rating in zip (titles , ratings )
16
+ }
17
+
18
+
19
+ def write_movies (filename : str = "IMDb_Top_250_Movies.csv" ) -> None :
20
+ movies = get_imdb_top_250_movies ()
21
+ with open (filename , "w" , newline = "" ) as out_file :
22
+ writer = csv .writer (out_file )
23
+ writer .writerow (["Movie title" , "IMDb rating" ])
24
+ for title , rating in movies .items ():
25
+ writer .writerow ([title , rating ])
26
+
27
+
28
+ if __name__ == "__main__" :
29
+ write_movies ()
You can’t perform that action at this time.
0 commit comments