2
2
import re
3
3
from bs4 import BeautifulSoup
4
4
5
+
5
6
# Gets top 250 movies from IMDB
6
7
def scrape_movies ():
7
8
@@ -14,8 +15,8 @@ def scrape_movies():
14
15
for i in range (len (movies )):
15
16
movie_string = movies [i ].get_text ()
16
17
movie = (' ' .join (movie_string .split ()).replace ('.' , '' ))
17
- movie_title = movie [len (str (i ))+ 1 :- 7 ]
18
- print (("| " + str (i + 1 )) + (" | " + movie_title ) + (" | Rating : " + "{:.1f}" .format (float (ratings [i ]))))
18
+ movie_title = movie [len (str (i )) + 1 :- 7 ]
19
+ print (("| " + str (i + 1 )) + (" | " + movie_title ) + (" | Rating : " + "{:.1f}" .format (float (ratings [i ]))))
19
20
return
20
21
21
22
@@ -24,7 +25,7 @@ def scrape_tvshows():
24
25
page = requests .get ("https://www.imdb.com/chart/toptv" )
25
26
Results = re .findall (r'" alt="(.+?)".*?title="(.*?)".*?strong.*?"(.*?)"' , page .text , re .DOTALL )
26
27
for i in range (len (Results )):
27
- print ("| " + str (i + 1 ) + " | " + Results [i ][0 ] + " | Rating : " + Results [i ][- 1 ][:3 ])
28
+ print ("| " + str (i + 1 ) + " | " + Results [i ][0 ] + " | Rating : " + Results [i ][- 1 ][:3 ])
28
29
29
30
return
30
31
@@ -40,12 +41,13 @@ def scrape_tvshows():
40
41
if val == 'Movies' :
41
42
globals ()['scrape_movies' ]()
42
43
print ("\n " )
43
- val = input ("Type 'Movies' or 'TV' or 'exit': " )
44
+ val = input ("Type 'Movies' or 'TV' or 'exit': " )
44
45
elif val == 'TV' :
45
46
globals ()['scrape_tvshows' ]()
46
47
print ("\n " )
47
- val = input ("Type 'Movies' or 'TV' or 'exit': " )
48
+ val = input ("Type 'Movies' or 'TV' or 'exit': " )
48
49
elif val == 'exit' :
49
50
val = ''
50
51
else :
51
- val = input ("Wrong Input. Try Again: " )
52
+ val = input ("Wrong Input. Try Again: " )
53
+
0 commit comments