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