From 8b52e442307d3d8a6f18468964381e2c2df16b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orkun=20=C4=B0ncili?= Date: Sun, 27 Oct 2019 23:48:38 +0300 Subject: [PATCH] Python program that listing top 'n' movie in imdb (#1477) * Python program that listing top 'n' movie in imdb * Update get_imdbtop.py --- web_programming/get_imdbtop.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 web_programming/get_imdbtop.py diff --git a/web_programming/get_imdbtop.py b/web_programming/get_imdbtop.py new file mode 100644 index 000000000..95fbeba7a --- /dev/null +++ b/web_programming/get_imdbtop.py @@ -0,0 +1,18 @@ +from bs4 import BeautifulSoup +import requests + + +def imdb_top(imdb_top_n): + base_url = (f"https://www.imdb.com/search/title?title_type=" + f"feature&sort=num_votes,desc&count={imdb_top_n}") + source = BeautifulSoup(requests.get(base_url).content, "html.parser") + for m in source.findAll("div", class_="lister-item mode-advanced"): + print("\n" + m.h3.a.text) # movie's name + print(m.find("span", attrs={"class": "genre"}).text) # genre + print(m.strong.text) # movie's rating + print(f"https://www.imdb.com{m.a.get('href')}") # movie's page link + print("*" * 40) + + +if __name__ == "__main__": + imdb_top(input("How many movies would you like to see? "))