- Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathq58.py
47 lines (34 loc) · 1.3 KB
/
q58.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Write a Python program to get movie name, year and a brief summary of the top 10 random movies.
__author__="Mahtab Alam"
frombs4importBeautifulSoup
importrequests
importrandom
defget_imd_movies(url):
page=requests.get(url)
soup=BeautifulSoup(page.text, 'html.parser')
movies=soup.find_all("td", class_="titleColumn")
random.shuffle(movies)
returnmovies
defget_imd_summary(url):
movie_page=requests.get(url)
soup=BeautifulSoup(movie_page.text, 'html.parser')
returnsoup.find("div", class_="summary_text").contents[0].strip()
defget_imd_movie_info(movie):
movie_title=movie.a.contents[0]
movie_year=movie.span.contents[0]
movie_url='http://www.imdb.com'+movie.a['href']
returnmovie_title, movie_year, movie_url
defimd_movie_picker():
ctr=0
print("================================================")
formovieinget_imd_movies('http://www.imdb.com/chart/top'):
movie_title, movie_year, movie_url=get_imd_movie_info(movie)
movie_summary=get_imd_summary(movie_url)
print(movie_title, movie_year)
print(movie_summary)
print("============================================")
ctr=ctr+1
if (ctr==10):
break
if__name__=='__main__':
imd_movie_picker()