You are on page 1of 3

PARSING THE WEB

Let´s find the following data for the first 100 movies:

Release Date Movie Production Budget

Código Implementado:
import requests
# Import the beautiful soup
from bs4 import BeautifulSoup
# Export library
import pandas as pd

TARGET_URL='https://www.the-numbers.com/movie/budgets/all'

info=[] # arreglo general


data={} # diccionoario final

myData=requests.get(TARGET_URL)
# Using beautiful soup library for parsing fetched data
soup= BeautifulSoup(myData.text, 'html.parser')
elements=soup.find_all("tr")
for elem in elements:
valores = []
dat = {}
itemtd=elem.find_all("td")
if itemtd:
valores.append(itemtd[1].text)
valores.append(itemtd[2].text)
valores.append(itemtd[3].text)

#se almacena la data en diccionarios con clave numérica por posición


dat[itemtd[0].text]=valores

#se agrega al arreglo general para crear el diccionario final


info.append(dat)

data["peliculas"]=info # se agraga para clave valor al diccionario data

dataFrame = pd.DataFrame.from_dict(data)
print(dataFrame)

Resultado al ejecutar el código:

You might also like