Python - How to use Beautiful Soup
Here I am attaching code for Python web Scraping
#Beautiful Soup is a Python package for parsing HTML and XML documents (including having malformed markup,
#i.e. non-closed tags, so named after tag soup). It creates a parse tree for parsed pages that can be used to extract data from HTML,
#which is useful for web scraping.
from bs4 import BeautifulSoup
import requests
import sys
url = 'http://www.imdb.com/chart/top'
response = requests.get(url)
#print(response.text)
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)
Watch video Python -Data Web Scraping -Real time interview question and solution online, duration hours minute second in high quality that is uploaded to the channel Technical RPA 04 August 2020. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 2,946 times and liked it 28 visitors.