Python Projects: Title, genre, rating and the url of the specific movie from IMDb movie database
Python Web Project-12 with Solution
Create a Python project to get the title, genre, rating and the url of the specific movie from IMDb movie database.
Details of movies:
https://www.imdb.com/
Sample Output:
How many movies would you like to see? 3 The Shawshank Redemption Drama 9.3 https://www.imdb.com/title/tt0111161/ **************************************** The Dark Knight Action, Crime, Drama 9.0 https://www.imdb.com/title/tt0468569/ **************************************** Inception Action, Adventure, Sci-Fi 8.8 https://www.imdb.com/title/tt1375666/ ****************************************
Sample Solution:
Python Code:
#Source https://bit.ly/3oiyn4p
import requests
from bs4 import BeautifulSoup
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? "))
Flowchart:
Improve this sample solutions and post your code through Disqus
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/projects/python/web-programming/python-web-programming-12.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics