download images from a list of image links just using beautifulsoap and requests nothing else

53 Views Asked by At

hello i am trying to download images of movies from a website using beautifulsoap and requests its any way to download them and save them with the name of the movie .jpg ? here is my code :

import requests
from bs4 import BeautifulSoup
import html
import pandas as pd

data = requests.get("https://parade.com/1222580/samuelmurrian/best-movies-all-time/").text

soap = BeautifulSoup(data, "html.parser")
tittle = soap.find_all(name="h3")
description = soap.find_all(name="p")
images = soap.find_all(name="img", class_="m-detail--tml-image m-image")
movie_data = []

for num in range(len(tittle)):
    local_data = {"Tittle": tittle[num].getText().replace("\xa0", ""),
                  "Description": html.unescape(description[num].getText()).replace(" ", "")}
    movie_name = tittle[num].getText().replace("\xa0", "")
    movie_data.append(local_data)
    url_base = "https://parade.com/"
    movie_image_link = images[num].get("src")
    

final_data = pd.DataFrame(movie_data)
final_data.to_csv("Data/100_movie_list.csv", mode="w", index=False)
1

There are 1 best solutions below

0
Talha Anwar On

You can do this in following way

import requests
filename = movie_image_link.split("/")[-1]
response = requests.get(movie_image_link)
with open(filename, 'wb') as f:
    f.write(response.content)