Hi friends,
In this post, we'll see a python script that takes a movie or a TV series name as an input and fetches its IMDB rating and summary from the IMDB website. The script uses Beautiful soup library in Python to extract the ratings and summary from the website. Here is the script to achieve the task.
import requests
from bs4 import BeautifulSoup
def getTitle(url):
html = requests.get(url)
soup = BeautifulSoup(html.text,'lxml')
for title in soup.findAll('div',{'class':'title_wrapper'}):
return title.find('h1').text.rstrip()
def getInfo(movieUrl):
html = requests.get(movieUrl)
soup = BeautifulSoup(html.text,'lxml')
for div in soup.findAll('div',{'class':'ratingValue'}):
print ('IMDB rating of \'' + userInput + '\' is: ', div.text)
print ()
for div in soup.findAll('div',{'class':'summary_text'}):
print ('Summary of \'' + userInput + '\' : ')
print (div.text.lstrip())
userInput = input(('Enter Movie/Tv series name : '))
print ()
url = 'http://www.imdb.com/find?ref_=nv_sr_fn&q=' + userInput + '&s=all'
html = requests.get(url)
soup = BeautifulSoup(html.text,'lxml')
for td in soup.findAll('td',{'class':'result_text'}):
link = td.find('a')['href']
movieUrl = 'http://www.imdb.com' + link
break
name = getTitle(movieUrl)
getInfo(movieUrl)
0 comments:
Post a Comment