|
1 | 1 | import requests |
2 | | -from bs4 import BeautifulSoup |
| 2 | +import json |
3 | 3 |
|
4 | 4 | # Defining variables and url |
5 | 5 | title = str(input("Enter the title of movie/series: ")) |
6 | | -release = str(input("Enter the year of release: ")) |
| 6 | +year = str(input("Enter the year of release: ")) |
7 | 7 | query = "+".join(title.split()) |
8 | | -#RL = f"https://www.imdb.com/search/title/?title={query}" |
9 | 8 |
|
10 | 9 | request_link = 'http://www.omdbapi.com/?i=tt3896198&apikey=2c84f11f' |
11 | 10 |
|
12 | | -#api_key = 2c84f11f |
| 11 | +#final request link using OMDb API |
| 12 | +request = request_link + '&t=' + query + '&y=' + year |
13 | 13 |
|
14 | | -request = request_link + '&t=' + query |
15 | | -result = requests.get(request) |
| 14 | +#requesting data from OMBd |
| 15 | +response = requests.get(request) |
16 | 16 |
|
17 | | -print(result.text) |
| 17 | +#converting to json (dictionary) |
| 18 | +response = response.json() |
18 | 19 |
|
19 | | -# s = requests.session() # Setting up session |
20 | | - |
21 | | -# try: |
22 | | -# response = s.get(URL) |
23 | | -# soup = BeautifulSoup(response.content, features="lxml") |
24 | | -# containers = soup.find_all("div", class_="lister-item-content") |
25 | | - |
26 | | -# for result in containers: |
27 | | -# name = result.h3.a.text.lower() |
28 | | -# year = result.h3.find( |
29 | | -# "span", class_="lister-item-year text-muted unbold" |
30 | | -# ).text.lower() |
31 | | - |
32 | | -# if title in name and release in year: |
33 | | -# rating = result.find("div", |
34 | | -# class_="inline-block ratings-imdb-rating")[ |
35 | | -# "data-value"] |
36 | | -# print(f"Rating of {name}:", rating) |
37 | | -# except Exception: |
38 | | -# print("Try again with valid combination of tile and release year") |
| 20 | +#printing imdb rating |
| 21 | +print(response['imdbRating']) |
0 commit comments