0

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)
Stink
  • 54
  • 8
  • I believe you can use `requests` for that, here is the [link](https://stackoverflow.com/questions/13137817/how-to-download-image-using-requests) – Talha Anwar Oct 23 '22 at 17:36
  • @TalhaAnwar look at the code - OP is already using `requests`... – MattDMo Oct 23 '22 at 17:38
  • @MattDMo yes and when i put my urls into the request.get i take 200 response back so its work my problem is downloading and saving them – Stink Oct 23 '22 at 17:44

1 Answers1

1

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)
Talha Anwar
  • 2,699
  • 4
  • 23
  • 62