-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie_list.py
26 lines (19 loc) · 875 Bytes
/
movie_list.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
# This is a mini project using Beautiful Soup to list the name of movies
# released in a particular year in order of popularity
from bs4 import BeautifulSoup
import requests
year = input()
# setting url with string concatenation and sending request
url = "http://www.imdb.com/search/title?release_date=" + year + "," + year + "&title_type=feature"
r = requests.get(url).content
data = BeautifulSoup(r,'lxml')
print(data.find('title').text)
movieList = data.findAll('div', attrs={'class': 'lister-item mode-advanced'})
i = 1
# finding the movie title from a large dictionary using HTML tags
for div_item in movieList:
div = div_item.find('div',attrs={'class':'lister-item-content'})
header = div.findChildren('h3',attrs={'class':'lister-item-header'})
print(str(i) + '.'),
print('Movie: ' + str((header[0].findChildren('a'))[0].contents[0]))
i += 1