-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimdb.py
More file actions
37 lines (22 loc) · 839 Bytes
/
imdb.py
File metadata and controls
37 lines (22 loc) · 839 Bytes
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
import requests
from bs4 import BeautifulSoup
def main():
year = input("Enter the year: ")
url = "http://www.imdb.com/search/title?at=0&sort=boxoffice_gross_us,desc&start=1&year={},{}".format(year,year)
r = requests.get(url)
soup = BeautifulSoup(r.content, "lxml")
movies_list = []
movies_rank = []
movies_earn = []
contents = soup.find_all('div', {"class": "lister-item-content"})
for item in contents:
movies_list.append(item.find('a').text)
movies_rank.append(item.find('strong').text)
earns = item.find_all('span',{"name": "nv"})
movies_earn.append(earns[1].text)
print("\n\n{:44} {:16} {}".format("Movie Name", "Ranking", "Earning"))
print("="*70)
All = ''.join('{:44} --> {:6} --> {}\n'.format(*t) for t in zip(movies_list, movies_rank, movies_earn))
print(All)
if __name__=="__main__":
main()