From cf4b88e765b0415b06ff6b03ebb14759b97a0d0d Mon Sep 17 00:00:00 2001 From: orkunincili Date: Sun, 27 Oct 2019 22:39:22 +0300 Subject: [PATCH 1/2] Python program that listing top 'n' movie in imdb --- web_programming/get_imdbtop.py | 21 +++++++++++++++++++++ 1 file changed, 21 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 000000000000..f60e3d40a810 --- /dev/null +++ b/web_programming/get_imdbtop.py @@ -0,0 +1,21 @@ + +from bs4 import BeautifulSoup +import requests + +def imdb_top(imdb_top_n): + base_url = "https://www.imdb.com/search/title?title_type=feature&sort=num_votes,desc&count="+imdb_top_n + r = requests.get(base_url) + source = BeautifulSoup(r.content, "lxml") + + top250 = source.findAll("div", attrs={"class": "lister-item mode-advanced"}) + + for i in top250: + print("\n"+i.find("h3").find("a").text) #movie's name + print(i.find("span", attrs={"class": "genre"}).text) #genre + print(i.find("strong").text) # movie's rating + print("https://www.imdb.com"+i.find("a").get("href")) #movie's page link + print("\n**************************************") + + +if __name__ == "__main__": + print(imdb_top(str(input()))) From 9ca8d1217bb58727a70aa1f5e4d48a229551802d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 27 Oct 2019 21:48:25 +0100 Subject: [PATCH 2/2] Update get_imdbtop.py --- web_programming/get_imdbtop.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/web_programming/get_imdbtop.py b/web_programming/get_imdbtop.py index f60e3d40a810..95fbeba7a772 100644 --- a/web_programming/get_imdbtop.py +++ b/web_programming/get_imdbtop.py @@ -1,21 +1,18 @@ - from bs4 import BeautifulSoup import requests -def imdb_top(imdb_top_n): - base_url = "https://www.imdb.com/search/title?title_type=feature&sort=num_votes,desc&count="+imdb_top_n - r = requests.get(base_url) - source = BeautifulSoup(r.content, "lxml") - - top250 = source.findAll("div", attrs={"class": "lister-item mode-advanced"}) - for i in top250: - print("\n"+i.find("h3").find("a").text) #movie's name - print(i.find("span", attrs={"class": "genre"}).text) #genre - print(i.find("strong").text) # movie's rating - print("https://www.imdb.com"+i.find("a").get("href")) #movie's page link - print("\n**************************************") +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__": - print(imdb_top(str(input()))) + imdb_top(input("How many movies would you like to see? "))