Python -Data Web Scraping -Real time interview question and solution

Опубликовано: 04 Август 2020
на канале: Technical RPA
2,946
28

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)


Смотрите видео Python -Data Web Scraping -Real time interview question and solution онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Technical RPA 04 Август 2020. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 2,946 раз и оно понравилось 28 посетителям.