0 votes
in Python by
Suppose you need to collect and print data from IMDb top 250 Movies page. Write a program in Python for doing so. (NOTE: - You can limit the displayed information for 3 fields; namely movie name, release year, and rating.)

1 Answer

0 votes
by
from bs4 import BeautifulSoup

import requests

import sys

url = 'http://www.imdb.com/chart/top'

response = requests.get(url)

soup = BeautifulSoup(response.text)

tr = soup.findChildren("tr")

tr = iter(tr)

next(tr)

for movie in tr:

title = movie.find('td', {'class': 'titleColumn'} ).find('a').contents[0]

year = movie.find('td', {'class': 'titleColumn'} ).find('span', {'class': 'secondaryInfo'}).contents[0]

rating = movie.find('td', {'class': 'ratingColumn imdbRating'} ).find('strong').contents[0]

row = title + ' - ' + year + ' ' + ' ' + rating

print(row)

Related questions

+2 votes
asked Feb 15, 2021 in Python by SakshiSharma
+2 votes
asked Feb 15, 2021 in Python by SakshiSharma
...