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